/*main.js,核心脚本*/

layui.use(['element', 'layer', 'form', 'laydate', 'jquery', 'table','upload'], function () {
    var element = layui.element;
    var layer = layui.layer;
    var form = layui.form;
    var laydate = layui.laydate;
    var $ = layui.jquery;
    var table = layui.table;
    var upload = layui.upload;

    /*layui表单验证规则*/
    form.verify({
        money: [/^\d+(\.\d{1,2})?|\s*$/, '金额格式不正确']
        , double: [/^[0-9]+\.?[0-9]+|\s*$/, '数据格式不正确，小数或整数']
    });


    let leftNav = {
        listWaybill:{//运单管理
            isHasAllAuth:0,
            isHasAuth: 0,
            "新增运单": 0,
            "运单列表": 0,
        },
        listTrans:{//运输管理
            isHasAllAuth:0,
            isHasAuth: 0,
            "装车配载": 0,
            "发车列表": 0,
        },
        listBypass:{//分流管理
            isHasAllAuth:0,
            isHasAuth: 0,
            "卸货入库": 0,
            "分流中心": 0,
            "派送列表": 0
        },
        listTrack:{//跟踪管理
            isHasAllAuth:0,
            isHasAuth: 0,
            "新增跟踪": 0,
            "新增签收": 0
        },
        listCheck:{//运单核对
            isHasAllAuth:0,
            isHasAuth: 0,
            "装车扫码":0,
            "装车序列":0,
            "卸货扫码":0,
            "卸货序列":0,
            "派送扫码":0,
            "派送序列":0,
            "签收扫码":0,
            "签收序列":0
        },
        listFinance:{//财务结算
            isHasAllAuth:0,
            isHasAuth: 0,
            "收入明细": 0,
            "开支明细": 0,
            "收支明细": 0
        },
        listCar:{//车辆管理
            isHasAllAuth:0,
            isHasAuth: 0,
            "车辆列表": 0,
            "车辆定位": 0
        },
        listCust:{//客户管理
            isHasAllAuth:0,
            isHasAuth: 0,
            "发货方客户": 0,
            "收货方客户": 0
        },
        listKpi:{//指标考核
            isHasAllAuth:0,
            isHasAuth: 0,
            "运单指标": 0,
            "运输指标": 0,
            "财务损益": 0
        },
        listPriceSet:{//价格管理
            isHasAllAuth:0,
            isHasAuth: 0,
            "价格列表": 0
        },
        listSys:{//系统管理
            isHasAllAuth:0,
            isHasAuth: 1,
            "资料修改": 0,
            "员工管理": 0,
            "分站管理": 0,
            "退出系统": 1,
        }
    };

    var navload = layer.load(1, {
        shade: [0.3, '#fff'], //0.1透明度的白色背景
    });
    /********************************权限验证*********************************/
    $.ajax({
        type: "POST",
        async: false,
        url: "/getLoginedEmp",
        success: function (data) {
            console.log(data);

            for (var i = 0; i < data["authorities"].length; i++) {
                if (data["authorities"][i]["authority"] == "运单管理"){
                    leftNav.listWaybill.isHasAllAuth = 1;
                }
                if (data["authorities"][i]["authority"] == "运输管理"){
                    leftNav.listTrans.isHasAllAuth = 1;
                }
                if (data["authorities"][i]["authority"] == "分流管理"){
                    leftNav.listBypass.isHasAllAuth = 1;
                }
                if (data["authorities"][i]["authority"] == "跟踪管理"){
                    leftNav.listTrack.isHasAllAuth = 1;
                }
                if (data["authorities"][i]["authority"] == "运单核对"){
                    leftNav.listCheck.isHasAllAuth = 1;
                }
                if (data["authorities"][i]["authority"] == "财务结算"){
                    leftNav.listFinance.isHasAllAuth = 1;
                }
                if (data["authorities"][i]["authority"] == "车辆管理"){
                    leftNav.listCar.isHasAllAuth = 1;
                }
                if (data["authorities"][i]["authority"] == "客户管理"){
                    leftNav.listCust.isHasAllAuth = 1;
                }
                if (data["authorities"][i]["authority"] == "指标考核"){
                    leftNav.listKpi.isHasAllAuth = 1;
                }
                if (data["authorities"][i]["authority"] == "公司管理"){
                    leftNav.listSys.isHasAllAuth = 1;
                }

                if(data["authorities"][i]["authority"] == "新增运单"){
                    if (leftNav.listWaybill.isHasAuth != 1){
                        leftNav.listWaybill.isHasAuth = 1;
                    }
                    leftNav.listWaybill['新增运单'] = 1;
                }
                if(data["authorities"][i]["authority"] == "运单列表"){
                    if (leftNav.listWaybill.isHasAuth != 1){
                        leftNav.listWaybill.isHasAuth = 1;
                    }
                    leftNav.listWaybill['运单列表'] = 1;
                }

                if(data["authorities"][i]["authority"] == "装车配货"){
                    if (leftNav.listTrans.isHasAuth != 1){
                        leftNav.listTrans.isHasAuth = 1;
                    }
                    leftNav.listTrans['装车配载'] = 1;
                }
                if(data["authorities"][i]["authority"] == "发车列表"){
                    if (leftNav.listTrans.isHasAuth != 1){
                        leftNav.listTrans.isHasAuth = 1;
                    }
                    leftNav.listTrans['发车列表'] = 1;
                }

                if(data["authorities"][i]["authority"] == "卸货入库"){
                    if (leftNav.listBypass.isHasAuth != 1){
                        leftNav.listBypass.isHasAuth = 1;
                    }
                    leftNav.listBypass['卸货入库'] = 1;
                }
                if(data["authorities"][i]["authority"] == "分流中心"){
                    if (leftNav.listBypass.isHasAuth != 1){
                        leftNav.listBypass.isHasAuth = 1;
                    }
                    leftNav.listBypass['分流中心'] = 1;
                }
                if(data["authorities"][i]["authority"] == "派送列表"){
                    if (leftNav.listBypass.isHasAuth != 1){
                        leftNav.listBypass.isHasAuth = 1;
                    }
                    leftNav.listBypass['派送列表'] = 1;
                }

                if(data["authorities"][i]["authority"] == "新增跟踪"){
                    if (leftNav.listTrack.isHasAuth != 1){
                        leftNav.listTrack.isHasAuth = 1;
                    }
                    leftNav.listTrack['新增跟踪'] = 1;
                }
                if(data["authorities"][i]["authority"] == "新增签收"){
                    if (leftNav.listTrack.isHasAuth != 1){
                        leftNav.listTrack.isHasAuth = 1;
                    }
                    leftNav.listTrack['新增签收'] = 1;
                }

                if(data["authorities"][i]["authority"] == "装车扫码"){
                    if (leftNav.listCheck.isHasAuth != 1){
                        leftNav.listCheck.isHasAuth = 1;
                    }
                    leftNav.listCheck['装车扫码'] = 1;
                }
                if(data["authorities"][i]["authority"] == "装车序列"){
                    if (leftNav.listCheck.isHasAuth != 1){
                        leftNav.listCheck.isHasAuth = 1;
                    }
                    leftNav.listCheck['装车序列'] = 1;
                }
                if(data["authorities"][i]["authority"] == "卸货扫码"){
                    if (leftNav.listCheck.isHasAuth != 1){
                        leftNav.listCheck.isHasAuth = 1;
                    }
                    leftNav.listCheck['卸货扫码'] = 1;
                }
                if(data["authorities"][i]["authority"] == "卸货序列"){
                    if (leftNav.listCheck.isHasAuth != 1){
                        leftNav.listCheck.isHasAuth = 1;
                    }
                    leftNav.listCheck['卸货序列'] = 1;
                }
                if(data["authorities"][i]["authority"] == "派送扫码"){
                    if (leftNav.listCheck.isHasAuth != 1){
                        leftNav.listCheck.isHasAuth = 1;
                    }
                    leftNav.listCheck['派送扫码'] = 1;
                }
                if(data["authorities"][i]["authority"] == "派送序列"){
                    if (leftNav.listCheck.isHasAuth != 1){
                        leftNav.listCheck.isHasAuth = 1;
                    }
                    leftNav.listCheck['派送序列'] = 1;
                }
                if(data["authorities"][i]["authority"] == "签收扫码"){
                    if (leftNav.listCheck.isHasAuth != 1){
                        leftNav.listCheck.isHasAuth = 1;
                    }
                    leftNav.listCheck['签收扫码'] = 1;
                }
                if(data["authorities"][i]["authority"] == "签收序列"){
                    if (leftNav.listCheck.isHasAuth != 1){
                        leftNav.listCheck.isHasAuth = 1;
                    }
                    leftNav.listCheck['签收序列'] = 1;
                }

                if(data["authorities"][i]["authority"] == "收入明细"){
                    if (leftNav.listFinance.isHasAuth != 1){
                        leftNav.listFinance.isHasAuth = 1;
                    }
                    leftNav.listFinance['收入明细'] = 1;
                }
                if(data["authorities"][i]["authority"] == "开支明细"){
                    if (leftNav.listFinance.isHasAuth != 1){
                        leftNav.listFinance.isHasAuth = 1;
                    }
                    leftNav.listFinance['开支明细'] = 1;
                }
                if(data["authorities"][i]["authority"] == "收支明细"){
                    if (leftNav.listFinance.isHasAuth != 1){
                        leftNav.listFinance.isHasAuth = 1;
                    }
                    leftNav.listFinance['收支明细'] = 1;
                }

                if(data["authorities"][i]["authority"] == "车辆列表"){
                    if (leftNav.listCar.isHasAuth != 1){
                        leftNav.listCar.isHasAuth = 1;
                    }
                    leftNav.listCar['车辆列表'] = 1;
                }
                if(data["authorities"][i]["authority"] == "车辆定位"){
                    if (leftNav.listCar.isHasAuth != 1){
                        leftNav.listCar.isHasAuth = 1;
                    }
                    leftNav.listCar['车辆定位'] = 1;
                }

                if(data["authorities"][i]["authority"] == "发货方列表"){
                    if (leftNav.listCust.isHasAuth != 1){
                        leftNav.listCust.isHasAuth = 1;
                    }
                    leftNav.listCust['发货方客户'] = 1;
                }
                if(data["authorities"][i]["authority"] == "收货方列表"){
                    if (leftNav.listCust.isHasAuth != 1){
                        leftNav.listCust.isHasAuth = 1;
                    }
                    leftNav.listCust['收货方客户'] = 1;
                }

                if(data["authorities"][i]["authority"] == "运单指标"){
                    if (leftNav.listKpi.isHasAuth != 1){
                        leftNav.listKpi.isHasAuth = 1;
                    }
                    leftNav.listKpi['运单指标'] = 1;
                }
                if(data["authorities"][i]["authority"] == "运输指标"){
                    if (leftNav.listKpi.isHasAuth != 1){
                        leftNav.listKpi.isHasAuth = 1;
                    }
                    leftNav.listKpi['运输指标'] = 1;
                }
                if(data["authorities"][i]["authority"] == "运单损益"){
                    if (leftNav.listKpi.isHasAuth != 1){
                        leftNav.listKpi.isHasAuth = 1;
                    }
                    leftNav.listKpi['运单损益'] = 1;
                }

                if(data["authorities"][i]["authority"] == "价格列表"){
                    if (leftNav.listPriceSet.isHasAuth != 1){
                        leftNav.listPriceSet.isHasAuth = 1;
                    }
                    leftNav.listPriceSet['价格列表'] = 1;
                }

                if(data["authorities"][i]["authority"] == "资料修改"){
                    if (leftNav.listSys.isHasAuth != 1){
                        leftNav.listSys.isHasAuth = 1;
                    }
                    leftNav.listSys['资料修改'] = 1;
                }
                if(data["authorities"][i]["authority"] == "员工管理"){
                    if (leftNav.listSys.isHasAuth != 1){
                        leftNav.listSys.isHasAuth = 1;
                    }
                    leftNav.listSys['员工管理'] = 1;
                }
                if(data["authorities"][i]["authority"] == "分站管理"){
                    if (leftNav.listSys.isHasAuth != 1){
                        leftNav.listSys.isHasAuth = 1;
                    }
                    leftNav.listSys['分站管理'] = 1;
                }

            }

            console.log(leftNav);
            flushLeftNav();
            layer.close(navload);
            function flushLeftNav() {
                //var list = "";

                //运单模块导航
                var waybill_li = "";
                var listWaybill = leftNav.listWaybill;
                if (listWaybill.isHasAllAuth != 0){
                    waybill_li =
                        '<li class="layui-nav-item list-waybill">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">运单管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;" class="nav-add-waybill">新增运单</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-waybill-list">运单列表</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listWaybill.isHasAuth != 0){
                    waybill_li =
                        '<li class="layui-nav-item list-waybill">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">运单管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listWaybill['新增运单'] != 0){
                        waybill_li += '<dd><a href="javascript:;" class="nav-add-waybill">新增运单</a></dd>';
                    }
                    if (listWaybill['运单列表'] != 0){
                        waybill_li += '<dd><a href="javascript:;" class="nav-waybill-list">运单列表</a></dd>';
                    }
                    waybill_li += '</dl></li>';
                }

                //运输模块导航
                var trans_li = "";
                var listTrans = leftNav.listTrans;
                if (listTrans.isHasAllAuth != 0){
                    trans_li =
                        '<li class="layui-nav-item list-trans">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">运输管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;" class="nav-carload">装车配载</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-trans-list">发车列表</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listTrans.isHasAuth != 0){
                    trans_li =
                        '<li class="layui-nav-item list-trans">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">运输管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listTrans['装车配载'] != 0){
                        trans_li += '<dd><a href="javascript:;" class="nav-carload">装车配载</a></dd>';
                    }
                    if (listTrans['发车列表'] != 0){
                        trans_li += '<dd><a href="javascript:;" class="nav-trans-list">发车列表</a></dd>';
                    }
                    trans_li += '</dl></li>';
                }

                //分流模块导航
                var bypass_li = "";
                var listBypass = leftNav.listBypass;
                if (listBypass.isHasAllAuth != 0){
                    bypass_li =
                        '<li class="layui-nav-item list-bypass">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">分流管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;" class="nav-unload-into">卸货入库</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-shunt-center">分流中心</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-send-list">派送列表</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listBypass.isHasAuth != 0){
                    bypass_li =
                        '<li class="layui-nav-item list-bypass">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">分流管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listBypass['卸货入库'] != 0){
                        bypass_li += '<dd><a href="javascript:;" class="nav-unload-into">卸货入库</a></dd>';
                    }
                    if (listBypass['分流中心'] != 0){
                        bypass_li += '<dd><a href="javascript:;" class="nav-shunt-center">分流中心</a></dd>';
                    }
                    if (listBypass['派送列表'] != 0){
                        bypass_li += '<dd><a href="javascript:;" class="nav-send-list">派送列表</a></dd>';
                    }

                    bypass_li += '</dl></li>';
                }

                //跟踪模块导航
                var track_li = "";
                var listTrack = leftNav.listTrack;
                if (listTrack.isHasAllAuth != 0){
                    track_li =
                        '<li class="layui-nav-item list-track">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">跟踪管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;" class="nav-add-track">新增跟踪</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-sign-for">新增签收</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listTrack.isHasAuth != 0){
                    track_li =
                        '<li class="layui-nav-item list-track">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">跟踪管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listTrack['新增跟踪'] != 0){
                        track_li += '<dd><a href="javascript:;" class="nav-add-track">新增跟踪</a></dd>';
                    }
                    if (listTrack['新增签收'] != 0){
                        track_li += '<dd><a href="javascript:;" class="nav-sign-for">新增签收</a></dd>';
                    }

                    track_li += '</dl></li>';
                }

                //核对管理模块导航
                var check_li = "";
                var listCheck = leftNav.listCheck;
                if (listCheck.isHasAllAuth != 0){
                    check_li =
                        '<li class="layui-nav-item list-check">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">核对管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;" class="nav-load-scan">装车扫码</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-load-sequ">装车序列</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-unload-scan">卸货扫码</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-unload-sequ">卸货序列</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-send-scan">派送扫码</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-send-sequ">派送序列</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-signfor-scan">签收扫码</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-signfor-sequ">签收序列</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listCheck.isHasAuth != 0){
                    check_li =
                        '<li class="layui-nav-item list-check">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">核对管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listCheck['装车扫码'] != 0){
                        check_li += '<dd><a href="javascript:;" class="nav-load-scan">装车扫码</a></dd>';
                    }
                    if (listCheck['装车序列'] != 0){
                        check_li += '<dd><a href="javascript:;" class="nav-load-sequ">装车序列</a></dd>';
                    }
                    if (listCheck['卸货扫码'] != 0){
                        check_li += '<dd><a href="javascript:;" class="nav-unload-scan">卸货扫码</a></dd>';
                    }
                    if (listCheck['卸货序列'] != 0){
                        check_li += '<dd><a href="javascript:;" class="nav-unload-sequ">卸货序列</a></dd>';
                    }
                    if (listCheck['派送扫码'] != 0){
                        check_li += '<dd><a href="javascript:;" class="nav-send-scan">派送扫码</a></dd>';
                    }
                    if (listCheck['派送序列'] != 0){
                        check_li += '<dd><a href="javascript:;" class="nav-send-sequ">派送序列</a></dd>';
                    }
                    if (listCheck['签收扫码'] != 0){
                        check_li += '<dd><a href="javascript:;" class="nav-signfor-scan">签收扫码</a></dd>';
                    }
                    if (listCheck['签收序列'] != 0){
                        check_li += '<dd><a href="javascript:;" class="nav-signfor-sequ">签收序列</a></dd>';
                    }

                    check_li += '</dl></li>';
                }

                //财务结算模块导航
                var finance_li = "";
                var listFinance = leftNav.listFinance;
                if (listFinance.isHasAllAuth != 0){
                    finance_li =
                        '<li class="layui-nav-item list-finance">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">财务结算</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;" class="nav-income">收入明细</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-spend">开支明细</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-inspend">收支明细</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listFinance.isHasAuth != 0){
                    finance_li =
                        '<li class="layui-nav-item list-finance">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">财务结算</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listFinance['收入明细'] != 0){
                        finance_li += '<dd><a href="javascript:;" class="nav-income">收入明细</a></dd>';
                    }
                    if (listFinance['开支明细'] != 0){
                        finance_li += '<dd><a href="javascript:;" class="nav-spend">开支明细</a></dd>';
                    }
                    if (listFinance['收支明细'] != 0){
                        finance_li += '<dd><a href="javascript:;" class="nav-inspend">收支明细</a></dd>';
                    }

                    finance_li += '</dl></li>';
                }

                //车辆管理模块导航
                var car_li = "";
                var listCar = leftNav.listCar;
                if (listCar.isHasAllAuth != 0){
                    car_li =
                        '<li class="layui-nav-item list-car">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">车辆管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;" class="nav-car-list">车辆列表</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-car-GPS">车辆定位</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listCar.isHasAuth != 0){
                    car_li =
                        '<li class="layui-nav-item list-car">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">车辆管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listCar['车辆列表'] != 0){
                        car_li += '<dd><a href="javascript:;" class="nav-car-list">车辆列表</a></dd>';
                    }
                    if (listCar['车辆定位'] != 0){
                        car_li += '<dd><a href="javascript:;" class="nav-car-GPS">车辆定位</a></dd>';
                    }

                    car_li += '</dl></li>';
                }

                //客户模块导航
                var cust_li = "";
                var listCust = leftNav.listCust;
                if (listCust.isHasAllAuth != 0){
                    cust_li =
                        '<li class="layui-nav-item list-cust">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">客户管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;" class="nav-shipper">发货方客户</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-consi">收货方客户</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listCust.isHasAuth != 0){
                    cust_li =
                        '<li class="layui-nav-item list-cust">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">客户管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listCust['发货方客户'] != 0){
                        cust_li += '<dd><a href="javascript:;" class="nav-shipper">发货方客户</a></dd>';
                    }
                    if (listCust['收货方客户'] != 0){
                        cust_li += '<dd><a href="javascript:;" class="nav-consi">收货方客户</a></dd>';
                    }

                    cust_li += '</dl></li>';
                }

                //指标考核模块导航
                var kpi_li = "";
                var listKpi = leftNav.listKpi;
                if (listKpi.isHasAllAuth != 0){
                    kpi_li =
                        '<li class="layui-nav-item list-kpi">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">指标考核</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;"class="nav-waybill-indicator">运单指标</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-carriage-indicator">运输指标</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-finance-profit">财务损益</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listKpi.isHasAuth != 0){
                    kpi_li =
                        '<li class="layui-nav-item list-kpi">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">指标考核</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listKpi['运单指标'] != 0){
                        kpi_li += '<dd><a href="javascript:;"class="nav-waybill-indicator">运单指标</a></dd>';
                    }
                    if (listKpi['运输指标'] != 0){
                        kpi_li += '<dd><a href="javascript:;" class="nav-carriage-indicator">运输指标</a></dd>';
                    }
                    if (listKpi['财务损益'] != 0){
                        kpi_li += '<dd><a href="javascript:;" class="nav-finance-profit">财务损益</a></dd>';
                    }

                    kpi_li += '</dl></li>';
                }

                //系统管理模块导航
                var sys_li = "";
                var listSys = leftNav.listSys;
                if (listSys.isHasAllAuth != 0){
                    sys_li =
                        '<li class="layui-nav-item list-sys">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">系统管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">' +
                        '<dd><a href="javascript:;" class="nav-sys-info">资料修改</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-emp-list">员工管理</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-subst-list">分站管理</a></dd>' +
                        '<dd><a href="javascript:;" class="nav-exit">退出系统</a></dd>' +
                        '</dl>'
                    '</li>';

                }else if (listSys.isHasAuth != 0){
                    sys_li =
                        '<li class="layui-nav-item list-sys">' +
                        '<a href="javascript:;">' +
                        '<i class="fa fa-desktop icon"></i><span class="text">系统管理</span>' +
                        '</a>' +
                        '<dl class="layui-nav-child">';
                    if (listSys['资料修改'] != 0){
                        sys_li += '<dd><a href="javascript:;" class="nav-sys-info">资料修改</a></dd>';
                    }
                    if (listSys['员工管理'] != 0){
                        sys_li += '<dd><a href="javascript:;" class="nav-emp-list">员工管理</a></dd>';
                    }
                    if (listSys['分站管理'] != 0){
                        sys_li += '<dd><a href="javascript:;" class="nav-subst-list">分站管理</a></dd>';
                    }
                    if (listSys['退出系统'] != 0){
                        sys_li += '<dd><a href="javascript:;" class="nav-exit">退出系统</a></dd>';
                    }

                    sys_li += '</dl></li>';
                }




                //左侧导航栏
                $("ul.main-left-nav").append(waybill_li+trans_li+bypass_li+track_li+check_li+finance_li+car_li+cust_li+kpi_li+sys_li);
                $("ul.main-left-nav").append('<div style="display: block;height: 50px;background: #3f4457;"></div>');
                element.render('nav');//刷新layui导航
            }

        }
    });

    //加载主页的报表统计
    // $.ajax({
    //     type: "POST",
    //     async: false,
    //     url: "/waybillVolume",
    //     dataType:"json",
    //     success: function (data) {
    //         console.log(data);
    //         loadWaybillCountBar(data);
    //         loadWaybillCountPie(data);
    //         setInterval(function () {
    //             $.ajax({
    //                 type: "POST",
    //                 url: "/waybillVolumeUpdate",
    //                 data:{
    //                     nowMonth: new Date().toDateString().split(" ")[1]
    //                 },
    //                 dataType:"json",
    //                 success: function (data) {
    //                     console.log(data);
    //                     loadWaybillCountBar(data);
    //                     loadWaybillCountPie(data);
    //                 }
    //             });
    //         },20000)

    //     }
    // });

    //echarts报表统计bar条形图加载
    function loadWaybillCountBar(data) {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init($(".chart-panel-bar").get(0));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '本年度运单数量-'+new Date().getFullYear()
            },
            tooltip: {},
            legend: {
                data:['运单成交量']
            },
            xAxis:{type: 'category'},
            yAxis: {},
            dataset:{
                source:[
                    ['一月',data[0]],
                    ['二月',data[1]],
                    ['三月',data[2]],
                    ['四月',data[3]],
                    ['五月',data[4]],
                    ['六月',data[5]],
                    ['七月',data[6]],
                    ['八月',data[7]],
                    ['九月',data[8]],
                    ['十月',data[9]],
                    ['十一月',data[10]],
                    ['十二月',data[11]]
                ]
            },
            series: [{
                type: 'bar',
                name: '运单成交量',
                encode: {x:0,y:1}
            }]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
    //加载运单饼状图
    function loadWaybillCountPie(data){
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init($(".chart-panel-pie").get(0));
        // 指定图表的配置项和数据
        var option = {
            tooltip: {},
            legend: {

            },
            series: [{
                type: 'pie',
                name: '运单成交量',
                data:[
                    {name:'一月',value:data[0]},
                    {name:'二月',value:data[1]},
                    {name:'三月',value:data[2]},
                    {name:'四月',value:data[3]},
                    {name:'五月',value:data[4]},
                    {name:'六月',value:data[5]},
                    {name:'七月',value:data[6]},
                    {name:'八月',value:data[7]},
                    {name:'九月',value:data[8]},
                    {name:'十月',value:data[9]},
                    {name:'十一月',value:data[10]},
                    {name:'十二月',value:data[11]}
                ]
            }]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }





    $(".list-check > .layui-nav-child > dd > a.nav-load-scan").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAddcheck .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }

            table.render({
                elem: '#userTable'
                , height: 430
                , url: '../selectall' //数据接口
                , id: 'listReload' //初始化标识id
                , page: true //开启分页
                , cols: [[ //表头
                    {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                    {field: 'check_date', title: '提交日期', width: 200, align: 'center'},
                    {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                    {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                            if (d.track.trackType =='2'){
                                       return '准备装车'
                            }else if(d.track.trackType =='3'){
                                return '已装车'
                            }else if(d.track.trackType =='1'){
                                return '发站库存'
                            }else if(d.track.trackType =='4'){
                                return '运输途中'
                            }else if(d.track.trackType =='5'){
                                return '到站库存'
                            }else if(d.track.trackType =='6'){
                                return '派送中'
                            }else if(d.track.trackType =='7'){
                                return '已签收'
                            }
                        }},
                    {
                        field: 'waybill.waybill_cargo_name',
                        title: '货名',
                        width: 120,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_cargo_count',
                        title: '总数量',
                        width: 100,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoCount}}</div>'
                    },
                    {field: 'check_load_count', title: '核对数', width: 80, align: 'center'},
                    {field: 'check_car_loading', title: '核对状态', width: 130, align: 'center'},
                    {
                        field: 'waybill.waybill_subst_id',
                        title: '到达分站',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.subst.substName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_billing_person',
                        title: '录入员',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillPromoter}}</div>'
                    },
                    {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}
                ]]

            })
            laydate.render({
                elem: '#TransTime'
                , type: 'datetime'
            });

            $("#her").click(function () {

                var num = $("#tid").val();

                table.reload('listReload', {
                    url: '/getoneCheck'
                    , method: 'post'
                    , where: {
                        check_waybill_consign_num: num
                    } //设定异步数据接口的额外参数
                    //,height: 300
                });

            });
            $("#btnaddgz").click(function () {
                $.ajax({
                    type: "post",
                    url: '../insertcheck',
                    data: {
                        mid: $("#TransportOrderCheck").val(),
                        timee: $("#TransTime").val()
                    },
                    dataType: "text",
                    success: function (date) {
                        sellall();
                    }
                });
            });
            form.render();


            table.on('tool(userTable)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

                var id = obj.data.check_id;
                var num = obj.data.check_waybill_consign_num;
                if (layEvent === 'del') { //删除
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            type: "post",
                            url: '../deletecheck',
                            data: {
                                check_id: id,
                                check_waybill_consign_num: num

                            },
                            dataType: "text",
                            success: function (date) {
                                //obj.del(); //删除对应行（tr）的DOM结构，并更新缓存

                                sellall();
                            }

                        });
                        layer.close(index);
                        //向服务端发送删除指令
                    });
                }
            });


        })

    });
    $(".list-check > .layui-nav-child > dd > a.nav-load-sequ").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAddtrucksequence .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            laydate.render({
                elem: '#CheckOrderdate1'

            });

//渲染下拉框
            layui.use('form', function () {
                var form = layui.form;
                var ids = ['1', '2'];
                var names = ['是', '否'];
                var select = document.getElementById('RiverTypeLevel');
                for (var i = 0; i < ids.length; i++) {
                    var option = document.createElement("option");
                    option.setAttribute("value", ids[i]);
                    option.innerText = names[i];
                    select.appendChild(option)
                }
                form.render("select");
            });

            table.render({
                elem: '#userTables'
                , height: 430
                , url: '../selectone' //数据接口
                , id: 'listReloadss' //初始化标识id
                , toolbar: "#toolBar"//显示左侧工具栏
                , cols: [[ //表头
                    {type: 'checkbox', sort: true, fixed: 'left'},
                    {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center',},
                    {
                        field: 'waybill_consign_date',
                        title: '托运日期',
                        width: 200,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillConsignDate}}</div>'
                    },
                    {title: '核对时间', width: 100, align: 'center', field: 'check_date'},
                    {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                    {
                        title: '交货日期',
                        width: 120,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillPromiseDate}}</div>'
                    },
                    {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                            if (d.track.trackType =='2'){
                                return '准备装车'
                            }else if(d.track.trackType =='3'){
                                return '已装车'
                            }else if(d.track.trackType =='1'){
                                return '发站库存'
                            }else if(d.track.trackType =='4'){
                                return '运输途中'
                            }else if(d.track.trackType =='5'){
                                return '到站库存'
                            }else if(d.track.trackType =='6'){
                                return '派送中'
                            }else if(d.track.trackType =='7'){
                                return '已签收'
                            }
                        }},
                    {title: '运输类型', width: 80, align: 'center', templet: '<div>{{d.waybill.waybillTransType}}</div>'},
                    {title: '货物名称', width: 130, align: 'center', templet: '<div>{{d.waybill.waybillCargoName}}</div>'},
                    {title: '总数量', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillCargoCount}}</div>'},
                    {field: 'check_load_count', title: '核对数', width: 160, align: 'center'},
                    {title: '包装', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillPackingWay}}</div>'},
                    {title: '总数量', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillCargoCount}}</div>'},
                    {title: '发货单位', width: 160, align: 'center', templet: '<div>{{d.shipper.shipperCom}}</div>'},
                    {title: '收货单位', width: 160, align: 'center', templet: '<div>{{d.consignee.consiCom}}</div>'},
                    {title: '收货人', width: 160, align: 'center', templet: '<div>{{d.consignee.consiPerson}}</div>'},
                    {title: '收货人电话', width: 160, align: 'center', templet: '<div>{{d.consignee.consiTelephone}}</div>'},
                    {title: '收货地址', width: 160, align: 'center', templet: '<div>{{d.consignee.consiAddress}}</div>'},
                    {title: '核对状态', width: 100, align: 'center', field: 'check_car_loading'},
                    {title: '备注', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillRemark}}</div>'},
                ]]
                ,done: function (res, curr, count) {
                    var that = this.elem.next();
                    res.data.forEach(function (item, index) {
                        if (item.check_car_loading === "是") {
                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                            tr.css("background-color", "block");
                            tr.css("color", "red");
                        }
                    });
                }

            })


            table.on('toolbar(userTables)', function (obj) {
                switch (obj.event) {
                    case 'insert':
                        opetitle = "添加";
                        break;
                    case 'update':
                        opetitle = "核对";
                        updateData(obj);
                        break;
                    case 'delete':
                        break;
                    default:
                        break;
                }
            });

            function updateData(obj) {
                layui.use(['layer', 'table', 'jquery'], function () {
                    var layer = layui.layer;
                    var table = layui.table;
                    var $ = layui.jquery;

                    layer.open({
                        title: opetitle,
                        content: '测试回调',
                        //大小
                        area: ['300px', '180px'],
                        btn: ['确定', '取消'],
                        content: '是否确定要核对选中行?',
                        yes: function (index, kskks) {
                            //获取复选框选中行，checkStatus
                            var checkStatus = table.checkStatus(obj.config.id);
                            //获取复选框选中行对象
                            var data = checkStatus.data;
                            var ids = [];

                            //因为是json格式所以循环
                            for (var i = 0; i < data.length; i++) {
                                // 将选中的行保存到数组
                                ids.push(data[i].check_id);

                            }

                            $.ajax({
                                url: '../updateload',
                                type: 'post',
                                dataType: 'text',
                                data: {

                                    ids: ids.join(',')
                                },
                                success: function (data) {
                                    table.render({
                                        elem: '#userTables'
                                        , height: 430
                                        , url: '../selectone' //数据接口
                                        , id: 'listReloadss' //初始化标识id
                                        , toolbar: "#toolBar"//显示左侧工具栏
                                        , cols: [[ //表头
                                            {type: 'checkbox', fixed: 'left'},
                                            {
                                                field: 'check_waybill_consign_num',
                                                title: '托运单号',
                                                width: 80,
                                                align: 'center'

                                            },
                                            {
                                                field: 'waybill_consign_date',
                                                title: '托运日期',
                                                width: 200,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillConsignDate}}</div>'

                                            },
                                            {title: '核对时间', width: 100, align: 'center', field: 'check_date'},
                                            {
                                                title: '到达城市',
                                                width: 100,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillReachCity}}</div>'

                                            },
                                            {
                                                title: '交货日期',
                                                width: 120,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillPromiseDate}}</div>'

                                            },
                                            {
                                                title: '运单状态',
                                                width: 100,
                                                align: 'center',
                                                templet: '<div>{{d.track.trackType}}</div>'
                                                ,templet: function (d) {
                                                    if (d.track.trackType =='2'){
                                                        return '准备装车'
                                                    }else if(d.track.trackType =='3'){
                                                        return '已装车'
                                                    }else if(d.track.trackType =='1'){
                                                        return '发站库存'
                                                    }else if(d.track.trackType =='4'){
                                                        return '运输途中'
                                                    }else if(d.track.trackType =='5'){
                                                        return '到站库存'
                                                    }else if(d.track.trackType =='6'){
                                                        return '派送中'
                                                    }else if(d.track.trackType =='7'){
                                                        return '已签收'
                                                    }
                                                }
                                            },
                                            {
                                                title: '运输类型',
                                                width: 80,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillTransType}}</div>'

                                            },
                                            {
                                                title: '货物名称',
                                                width: 130,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoName}}</div>'

                                            },
                                            {
                                                title: '总数量',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoCount}}</div>'

                                            },
                                            {field: 'check_load_count', title: '核对数', width: 160, align: 'center'},
                                            {
                                                title: '包装',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillPackingWay}}</div>'

                                            },
                                            {
                                                title: '总数量',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoCount}}</div>'

                                            },
                                            {
                                                title: '发货单位',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.shipper.shipperCom}}</div>'

                                            },
                                            {
                                                title: '收货单位',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiCom}}</div>'

                                            },
                                            {
                                                title: '收货人',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiPerson}}</div>'

                                            },
                                            {
                                                title: '收货人电话',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiTelephone}}</div>'

                                            },
                                            {
                                                title: '收货地址',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiAddress}}</div>'

                                            },
                                            {title: '核对状态', width: 100, align: 'center', field: 'check_car_loading'},
                                            {
                                                title: '备注',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillRemark}}</div>'

                                            },
                                        ]]
                                        ,done: function (res, curr, count) {
                                            var that = this.elem.next();
                                            res.data.forEach(function (item, index) {
                                                if (item.check_car_loading === "是") {
                                                    var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                                                    tr.css("background-color", "block");
                                                    tr.css("color", "red");
                                                }
                                            });
                                        }
                                    })

                                    layer.close(index);
                                }
                            });
                        }
                    });
                });

            }

            $("#btnaddgzss").click(function () {

                var num = $("#TransportOrderID").val();
                var num1 = $("select#RiverTypeLevel + .layui-form-select dl dd.layui-this").text();
                var num2 = $("#ShipmentsCompany").val();
                var num3 = $("#CheckOrderdate1").val();
                var num4 = $("#ComeCity").val();

                console.log("num1");
                table.reload('listReloadss', {
                    url: '/selectallyuju'
                    , method: 'post'
                    , where: {
                        check_waybill_consign_num: num,
                        check_car_loading: num1,
                        shipper_com: num2,
                        check_date: num3,
                        waybill_reach_city: num4
                    } //设定异步数据接口的额外参数
                    //,height: 30

                });

            });
        })
    });


    $(".list-check > .layui-nav-child > dd > a.nav-unload-scan").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAddunloadscan .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            table.render({
                elem: '#userTable'
                , height: 430
                , url: '../getunloadCheck' //数据接口
                , id: 'listReloadsss' //初始化标识id
                , page: true //开启分页
                , cols: [[ //表头
                    {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                    {field: 'check_date', title: '提交日期', width: 200, align: 'center'},
                    {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                    {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                            if (d.track.trackType =='2'){
                                return '准备装车'
                            }else if(d.track.trackType =='3'){
                                return '已装车'
                            }else if(d.track.trackType =='1'){
                                return '发站库存'
                            }else if(d.track.trackType =='4'){
                                return '运输途中'
                            }else if(d.track.trackType =='5'){
                                return '到站库存'
                            }else if(d.track.trackType =='6'){
                                return '派送中'
                            }else if(d.track.trackType =='7'){
                                return '已签收'
                            }
                        }},
                    {
                        field: 'waybill.waybill_cargo_name',
                        title: '货名',
                        width: 120,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_cargo_count',
                        title: '总数量',
                        width: 100,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoCount}}</div>'
                    },
                    {field: 'check_unload_count', title: '核对数', width: 80, align: 'center'},
                    {field: 'check_car_loading', title: '核对状态', width: 130, align: 'center'},
                    {

                        title: '到达分站',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.subst.substName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_billing_person',
                        title: '录入员',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillPromoter}}</div>'
                    },
                    {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}
                ]]

            })
            laydate.render({
                elem: '#TransTime'
                , type: 'datetime'
            });
            $("#btnaddgz").click(function () {
                $.ajax({
                    type: "post",
                    url: '../insertunload',
                    data: {
                        mid: $("#TransportOrderCheck").val(),
                        timee: $("#TransTime").val()
                    },
                    dataType: "text",
                    success: function (date) {
                        sellalles();
                    }
                });
            });
            form.render();
            $("#her").click(function () {

                var num = $("#tid").val();

                table.reload('listReloadsss', {
                    url: '/getoneCheck1'
                    , method: 'post'
                    , where: {
                        check_waybill_consign_num: num
                    } //设定异步数据接口的额外参数
                    //,height: 300
                });

            });


            table.on('tool(userTable)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
                alert(data.check_id);
                var id = obj.data.check_id;
                var num = obj.data.check_waybill_consign_num;
                if (layEvent === 'del') { //删除
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            type: "post",
                            url: '../deletecheck1',
                            data: {
                                check_id: id,
                                check_waybill_consign_num: num

                            },
                            dataType: "text",
                            success: function (date) {
                                //obj.del(); //删除对应行（tr）的DOM结构，并更新缓存

                                sellalles();
                            }

                        });
                        layer.close(index);
                        //向服务端发送删除指令
                    });
                }
            });


        })
    });
    $(".list-check > .layui-nav-child > dd > a.nav-unload-sequ").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAddunloadsequence .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            laydate.render({
                elem: '#CheckOrderdate1'

            });
            layui.use('form', function () {
                var form = layui.form;
                var ids = ['1', '2'];
                var names = ['是', '否'];
                var select = document.getElementById('RiverTypeLevel');
                for (var i = 0; i < ids.length; i++) {
                    var option = document.createElement("option");
                    option.setAttribute("value", ids[i]);
                    option.innerText = names[i];
                    select.appendChild(option)
                }
                form.render("select");
            });
            table.render({
                elem: '#userTables'
                , height: 430
                , url: '../selectone1' //数据接口
                , id: 'listReloadss' //初始化标识id
                , toolbar: "#toolBar"//显示左侧工具栏
                , cols: [[ //表头
                    {type: 'checkbox', sort: true, fixed: 'left'},
                    {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                    {
                        field: 'waybill_consign_date',
                        title: '托运日期',
                        width: 200,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillConsignDate}}</div>'
                    },
                    {title: '核对时间', width: 100, align: 'center', field: 'check_date'},
                    {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                    {
                        title: '交货日期',
                        width: 120,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillPromiseDate}}</div>'
                    },
                    {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                            if (d.track.trackType ==2){
                                return '准备装车'
                            }else if(d.track.trackType =='3'){
                                return '已装车'
                            }else if(d.track.trackType =='1'){
                                return '发站库存'
                            }else if(d.track.trackType =='4'){
                                return '运输途中'
                            }else if(d.track.trackType =='5'){
                                return '到站库存'
                            }else if(d.track.trackType =='6'){
                                return '派送中'
                            }else if(d.track.trackType =='7'){
                                return '已签收'
                            }
                        }},
                    {title: '运输类型', width: 80, align: 'center', templet: '<div>{{d.waybill.waybillTransType}}</div>'},
                    {title: '货物名称', width: 130, align: 'center', templet: '<div>{{d.waybill.waybillCargoName}}</div>'},
                    {title: '总数量', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillCargoCount}}</div>'},
                    {field: 'check_unload_count', title: '核对数', width: 160, align: 'center'},
                    {title: '包装', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillPackingWay}}</div>'},
                    {title: '总数量', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillCargoCount}}</div>'},
                    {title: '发货单位', width: 160, align: 'center', templet: '<div>{{d.shipper.shipperCom}}</div>'},
                    {title: '收货单位', width: 160, align: 'center', templet: '<div>{{d.consignee.consiCom}}</div>'},
                    {title: '收货人', width: 160, align: 'center', templet: '<div>{{d.consignee.consiPerson}}</div>'},
                    {title: '收货人电话', width: 160, align: 'center', templet: '<div>{{d.consignee.consiTelephone}}</div>'},
                    {title: '收货地址', width: 160, align: 'center', templet: '<div>{{d.consignee.consiAddress}}</div>'},
                    {title: '核对状态', width: 100, align: 'center', field: 'check_car_loading'},
                    {title: '备注', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillRemark}}</div>'},
                ]]
                ,done: function (res, curr, count) {
                    var that = this.elem.next();
                    res.data.forEach(function (item, index) {
                        if (item.check_car_loading === "是") {
                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                            tr.css("background-color", "block");
                            tr.css("color", "red");
                        }
                    });
                }

            })



            table.on('toolbar(userTables)', function (obj) {
                switch (obj.event) {
                    case 'insert':
                        opetitle = "添加";
                        break;
                    case 'update':
                        opetitle = "核对";
                        updateData(obj);
                        break;
                    case 'delete':
                        break;
                    default:
                        break;
                }
            });


            function updateData(obj) {
                layui.use(['layer', 'table', 'jquery'], function () {
                    var layer = layui.layer;
                    var table = layui.table;
                    var $ = layui.jquery;
                    layer.open({
                        title: opetitle,
                        content: '测试回调',
                        //大小
                        area: ['300px', '180px'],
                        btn: ['确定', '取消'],
                        content: '是否确定要核对选中行?',
                        yes: function (index, kskks) {
                            //获取复选框选中行，checkStatus
                            var checkStatus = table.checkStatus(obj.config.id);
                            //获取复选框选中行对象
                            var data = checkStatus.data;
                            var ids = [];
                            //因为是json格式所以循环
                            for (var i = 0; i < data.length; i++) {
                                // 将选中的行保存到数组
                                ids.push(data[i].check_id);
                            }
                            $.ajax({
                                url: '../updateload',
                                type: 'post',
                                dataType: 'text',
                                data: {

                                    ids: ids.join(',')
                                },
                                success: function (data) {
                                    table.render({
                                        elem: '#userTables'
                                        , height: 430
                                        , url: '../selectone1' //数据接口
                                        , id: 'listReloadss' //初始化标识id
                                        , toolbar: "#toolBar"//显示左侧工具栏
                                        , cols: [[ //表头
                                            {type: 'checkbox', fixed: 'left'},
                                            {
                                                field: 'check_waybill_consign_num',
                                                title: '托运单号',
                                                width: 80,
                                                align: 'center'

                                            },
                                            {
                                                field: 'waybill_consign_date',
                                                title: '托运日期',
                                                width: 200,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillConsignDate}}</div>'

                                            },
                                            {title: '核对时间', width: 100, align: 'center', field: 'check_date'},
                                            {
                                                title: '到达城市',
                                                width: 100,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillReachCity}}</div>'

                                            },
                                            {
                                                title: '交货日期',
                                                width: 120,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillPromiseDate}}</div>'

                                            },
                                            {
                                                title: '运单状态',
                                                width: 100,
                                                align: 'center',
                                                templet: '<div>{{d.track.trackType}}</div>'
                                                ,templet: function (d) {
                                                    if (d.track.trackType =='2'){
                                                        return '准备装车'
                                                    }else if(d.track.trackType =='3'){
                                                        return '已装车'
                                                    }else if(d.track.trackType =='1'){
                                                        return '发站库存'
                                                    }else if(d.track.trackType =='4'){
                                                        return '运输途中'
                                                    }else if(d.track.trackType =='5'){
                                                        return '到站库存'
                                                    }else if(d.track.trackType =='6'){
                                                        return '派送中'
                                                    }else if(d.track.trackType =='7'){
                                                        return '已签收'
                                                    }
                                                }
                                            },
                                            {
                                                title: '运输类型',
                                                width: 80,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillTransType}}</div>'

                                            },
                                            {
                                                title: '货物名称',
                                                width: 130,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoName}}</div>'

                                            },
                                            {
                                                title: '总数量',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoCount}}</div>'

                                            },
                                            {field: 'check_unload_count', title: '核对数', width: 160, align: 'center'},
                                            {
                                                title: '包装',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillPackingWay}}</div>'

                                            },
                                            {
                                                title: '总数量',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoCount}}</div>'

                                            },
                                            {
                                                title: '发货单位',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.shipper.shipperCom}}</div>'

                                            },
                                            {
                                                title: '收货单位',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiCom}}</div>'

                                            },
                                            {
                                                title: '收货人',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiPerson}}</div>'

                                            },
                                            {
                                                title: '收货人电话',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiTelephone}}</div>'

                                            },
                                            {
                                                title: '收货地址',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiAddress}}</div>'

                                            },
                                            {title: '核对状态', width: 100, align: 'center', field: 'check_car_loading'},
                                            {
                                                title: '备注',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillRemark}}</div>'

                                            },
                                        ]]
                                        ,done: function (res, curr, count) {
                                            var that = this.elem.next();
                                            res.data.forEach(function (item, index) {
                                                if (item.check_car_loading === "是") {
                                                    var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                                                    tr.css("background-color", "block");
                                                    tr.css("color", "red");
                                                }
                                            });
                                        }
                                    })

                                    layer.close(index);
                                }
                            });
                        }
                    });
                });

            }


            $("#btnaddgzss").click(function () {

                var num = $("#TransportOrderID").val();
                var num1 = $("select#RiverTypeLevel + .layui-form-select dl dd.layui-this").text();
                var num2 = $("#ShipmentsCompany").val();
                var num3 = $("#CheckOrderdate1").val();
                var num4 = $("#ComeCity").val();

                console.log("num1");
                table.reload('listReloadss', {
                    url: '/selectallyuju1'
                    , method: 'post'
                    , where: {
                        check_waybill_consign_num: num,
                        check_car_loading: num1,
                        shipper_com: num2,
                        check_date: num3,
                        waybill_reach_city: num4
                    } //设定异步数据接口的额外参数
                    //,height: 30

                });

            });

        })
    });

    $(".list-check > .layui-nav-child > dd > a.nav-send-scan").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAdddeliveryscan .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            table.render({
                elem: '#userTable'
                , height: 430
                , url: '../getAlldelivery' //数据接口
                , id: 'listReloadssse' //初始化标识id
                , page: true //开启分页
                , cols: [[ //表头
                    {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                    {field: 'check_date', title: '提交日期', width: 200, align: 'center'},
                    {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                    {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                            if (d.track.trackType =='2'){
                                return '准备装车'
                            }else if(d.track.trackType =='3'){
                                return '已装车'
                            }else if(d.track.trackType =='1'){
                                return '发站库存'
                            }else if(d.track.trackType =='4'){
                                return '运输途中'
                            }else if(d.track.trackType =='5'){
                                return '到站库存'
                            }else if(d.track.trackType =='6'){
                                return '派送中'
                            }else if(d.track.trackType =='7'){
                                return '已签收'
                            }
                        }},
                    {
                        field: 'waybill.waybill_cargo_name',
                        title: '货名',
                        width: 120,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_cargo_count',
                        title: '总数量',
                        width: 100,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoCount}}</div>'
                    },
                    {field: 'check_delivery_count', title: '核对数', width: 80, align: 'center'},
                    {field: 'check_car_loading', title: '核对状态', width: 130, align: 'center'},
                    {

                        title: '到达分站',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.subst.substName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_billing_person',
                        title: '录入员',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillPromoter}}</div>'
                    },
                    {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}
                ]]

            })

            laydate.render({
                elem: '#TransTime'
                , type: 'datetime'
            });
            $("#btnaddgz").click(function () {
                $.ajax({
                    type: "post",
                    url: '../insertdelivery',
                    data: {
                        mid: $("#TransportOrderCheck").val(),
                        timee: $("#TransTime").val()
                    },
                    dataType: "text",
                    success: function (date) {
                        selldeliver();
                    }
                });
            });
            form.render();

            $("#her").click(function () {

                var num = $("#tid").val();

                table.reload('listReloadssse', {
                    url: '/getonedelivery'
                    , method: 'post'
                    , where: {
                        check_waybill_consign_num: num
                    } //设定异步数据接口的额外参数
                    //,height: 300
                });

            });


            table.on('tool(userTable)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

                var id = obj.data.check_id;
                var num = obj.data.check_waybill_consign_num;
                if (layEvent === 'del') { //删除
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            type: "post",
                            url: '../deletedelivery',
                            data: {
                                check_id: id,
                                check_waybill_consign_num: num

                            },
                            dataType: "text",
                            success: function (date) {
                                //obj.del(); //删除对应行（tr）的DOM结构，并更新缓存

                                selldeliver();
                            }

                        });
                        layer.close(index);
                        //向服务端发送删除指令
                    });
                }
            });
        })
    });
    $(".list-check > .layui-nav-child > dd > a.nav-send-sequ").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAdddeliverylist .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            laydate.render({
                elem: '#CheckOrderdate1'

            });
            layui.use('form', function () {
                var form = layui.form;
                var ids = ['1', '2'];
                var names = ['是', '否'];
                var select = document.getElementById('RiverTypeLevel');
                for (var i = 0; i < ids.length; i++) {
                    var option = document.createElement("option");
                    option.setAttribute("value", ids[i]);
                    option.innerText = names[i];
                    select.appendChild(option)
                }
                form.render("select");
            });

            table.render({
                elem: '#userTables'
                , height: 430
                , url: '../selectdeliverylist' //数据接口
                , id: 'listReloadeess' //初始化标识id
                , toolbar: "#toolBar"//显示左侧工具栏
                , cols: [[ //表头
                    {type: 'checkbox', sort: true, fixed: 'left'},
                    {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                    {
                        field: 'waybill_consign_date',
                        title: '托运日期',
                        width: 200,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillConsignDate}}</div>'
                    },
                    {title: '核对时间', width: 100, align: 'center', field: 'check_date'},
                    {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                    {
                        title: '交货日期',
                        width: 120,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillPromiseDate}}</div>'
                    },
                    {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                            if (d.track.trackType =='2'){
                                return '准备装车'
                            }else if(d.track.trackType =='3'){
                                return '已装车'
                            }else if(d.track.trackType =='1'){
                                return '发站库存'
                            }else if(d.track.trackType =='4'){
                                return '运输途中'
                            }else if(d.track.trackType =='5'){
                                return '到站库存'
                            }else if(d.track.trackType =='6'){
                                return '派送中'
                            }else if(d.track.trackType =='7'){
                                return '已签收'
                            }
                        }},
                    {title: '运输类型', width: 80, align: 'center', templet: '<div>{{d.waybill.waybillTransType}}</div>'},
                    {title: '货物名称', width: 130, align: 'center', templet: '<div>{{d.waybill.waybillCargoName}}</div>'},
                    {title: '总数量', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillCargoCount}}</div>'},
                    {field: 'check_delivery_count', title: '核对数', width: 160, align: 'center'},
                    {title: '包装', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillPackingWay}}</div>'},
                    {title: '总数量', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillCargoCount}}</div>'},
                    {title: '发货单位', width: 160, align: 'center', templet: '<div>{{d.shipper.shipperCom}}</div>'},
                    {title: '收货单位', width: 160, align: 'center', templet: '<div>{{d.consignee.consiCom}}</div>'},
                    {title: '收货人', width: 160, align: 'center', templet: '<div>{{d.consignee.consiPerson}}</div>'},
                    {title: '收货人电话', width: 160, align: 'center', templet: '<div>{{d.consignee.consiTelephone}}</div>'},
                    {title: '收货地址', width: 160, align: 'center', templet: '<div>{{d.consignee.consiAddress}}</div>'},
                    {title: '核对状态', width: 100, align: 'center', field: 'check_car_loading'},
                    {title: '备注', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillRemark}}</div>'},
                ]]
                ,done: function (res, curr, count) {
                    var that = this.elem.next();
                    res.data.forEach(function (item, index) {
                        if (item.check_car_loading === "是") {
                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                            tr.css("background-color", "block");
                            tr.css("color", "red");
                        }
                    });
                }

            })


            table.on('toolbar(userTables)', function (obj) {
                switch (obj.event) {
                    case 'insert':
                        opetitle = "添加";
                        break;
                    case 'update':
                        opetitle = "核对";
                        updateData(obj);
                        break;
                    case 'delete':
                        break;
                    default:
                        break;
                }
            });


            function updateData(obj) {
                layui.use(['layer', 'table', 'jquery'], function () {
                    var layer = layui.layer;
                    var table = layui.table;
                    var $ = layui.jquery;
                    layer.open({
                        title: opetitle,
                        content: '测试回调',
                        //大小
                        area: ['300px', '180px'],
                        btn: ['确定', '取消'],
                        content: '是否确定要核对选中行?',
                        yes: function (index, kskks) {
                            //获取复选框选中行，checkStatus
                            var checkStatus = table.checkStatus(obj.config.id);
                            //获取复选框选中行对象
                            var data = checkStatus.data;
                            var ids = [];
                            //因为是json格式所以循环
                            for (var i = 0; i < data.length; i++) {
                                // 将选中的行保存到数组
                                ids.push(data[i].check_id);
                            }
                            $.ajax({
                                url: '../updateload',
                                type: 'post',
                                dataType: 'text',
                                data: {

                                    ids: ids.join(',')
                                },
                                success: function (data) {
                                    table.render({
                                        elem: '#userTables'
                                        , height: 430
                                        , url: '../selectdeliverylist' //数据接口
                                        , id: 'listReloadeess' //初始化标识id
                                        , toolbar: "#toolBar"//显示左侧工具栏
                                        , cols: [[ //表头
                                            {type: 'checkbox', fixed: 'left'},
                                            {
                                                field: 'check_waybill_consign_num',
                                                title: '托运单号',
                                                width: 80,
                                                align: 'center'

                                            },
                                            {
                                                field: 'waybill_consign_date',
                                                title: '托运日期',
                                                width: 200,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillConsignDate}}</div>'

                                            },
                                            {title: '核对时间', width: 100, align: 'center', field: 'check_date'},
                                            {
                                                title: '到达城市',
                                                width: 100,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillReachCity}}</div>'

                                            },
                                            {
                                                title: '交货日期',
                                                width: 120,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillPromiseDate}}</div>'

                                            },
                                            {
                                                title: '运单状态',
                                                width: 100,
                                                align: 'center',
                                                templet: '<div>{{d.track.trackType}}</div>'
                                                ,templet: function (d) {
                                                    if (d.track.trackType =='2'){
                                                        return '准备装车'
                                                    }else if(d.track.trackType =='3'){
                                                        return '已装车'
                                                    }else if(d.track.trackType =='1'){
                                                        return '发站库存'
                                                    }else if(d.track.trackType =='4'){
                                                        return '运输途中'
                                                    }else if(d.track.trackType =='5'){
                                                        return '到站库存'
                                                    }else if(d.track.trackType =='6'){
                                                        return '派送中'
                                                    }else if(d.track.trackType =='7'){
                                                        return '已签收'
                                                    }
                                                }
                                            },
                                            {
                                                title: '运输类型',
                                                width: 80,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillTransType}}</div>'

                                            },
                                            {
                                                title: '货物名称',
                                                width: 130,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoName}}</div>'

                                            },
                                            {
                                                title: '总数量',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoCount}}</div>'

                                            },
                                            {field: 'check_unload_count', title: '核对数', width: 160, align: 'center'},
                                            {
                                                title: '包装',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillPackingWay}}</div>'

                                            },
                                            {
                                                title: '总数量',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoCount}}</div>'

                                            },
                                            {
                                                title: '发货单位',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.shipper.shipperCom}}</div>'

                                            },
                                            {
                                                title: '收货单位',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiCom}}</div>'

                                            },
                                            {
                                                title: '收货人',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiPerson}}</div>'

                                            },
                                            {
                                                title: '收货人电话',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiTelephone}}</div>'

                                            },
                                            {
                                                title: '收货地址',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiAddress}}</div>'

                                            },
                                            {title: '核对状态', width: 100, align: 'center', field: 'check_car_loading'},
                                            {
                                                title: '备注',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillRemark}}</div>'

                                            },
                                        ]]
                                        ,done: function (res, curr, count) {
                                            var that = this.elem.next();
                                            res.data.forEach(function (item, index) {
                                                if (item.check_car_loading === "是") {
                                                    var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                                                    tr.css("background-color", "block");
                                                    tr.css("color", "red");
                                                }
                                            });
                                        }
                                    })

                                    layer.close(index);
                                }
                            });
                        }
                    });
                });

            }
            $("#btnaddgzss").click(function () {

                var num = $("#TransportOrderID").val();
                var num1 = $("select#RiverTypeLevel + .layui-form-select dl dd.layui-this").text();
                var num2 = $("#ShipmentsCompany").val();
                var num3 = $("#CheckOrderdate1").val();
                var num4 = $("#ComeCity").val();

                console.log("num1");
                table.reload('listReloadeess', {
                    url: '/selectallyuju2'
                    , method: 'post'
                    , where: {
                        check_waybill_consign_num: num,
                        check_car_loading: num1,
                        shipper_com: num2,
                        check_date: num3,
                        waybill_reach_city: num4
                    } //设定异步数据接口的额外参数
                    //,height: 30

                });

            });

        })
    });

    $(".list-check > .layui-nav-child > dd > a.nav-signfor-scan").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAdddsigner .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            table.render({
                elem: '#userTable'
                , height: 430
                , url: '../getAllsigner' //数据接口
                , id: 'listReloadas' //初始化标识id
                , page: true //开启分页
                , cols: [[ //表头
                    {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                    {field: 'check_date', title: '提交日期', width: 200, align: 'center'},
                    {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                    {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                            if (d.track.trackType =='2'){
                                return '准备装车'
                            }else if(d.track.trackType =='3'){
                                return '已装车'
                            }else if(d.track.trackType =='1'){
                                return '发站库存'
                            }else if(d.track.trackType =='4'){
                                return '运输途中'
                            }else if(d.track.trackType =='5'){
                                return '到站库存'
                            }else if(d.track.trackType =='6'){
                                return '派送中'
                            }else if(d.track.trackType =='7'){
                                return '已签收'
                            }
                        }},
                    {
                        field: 'waybill.waybill_cargo_name',
                        title: '货名',
                        width: 120,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_cargo_count',
                        title: '总数量',
                        width: 100,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoCount}}</div>'
                    },
                    {field: 'check_sign_count', title: '核对数', width: 80, align: 'center'},
                    {field: 'check_car_loading', title: '核对状态', width: 130, align: 'center'},
                    {

                        title: '到达分站',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.subst.substName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_billing_person',
                        title: '录入员',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillPromoter}}</div>'
                    },
                    {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}
                ]]

            })
            laydate.render({
                elem: '#TransTime'
                , type: 'datetime'
            });
            $("#btnaddgz").click(function () {
                $.ajax({
                    type: "post",
                    url: '../insertsigner',
                    data: {
                        mid: $("#TransportOrderCheck").val(),
                        timee: $("#TransTime").val()
                    },
                    dataType: "text",
                    success: function (date) {
                        sellsigner();
                    }
                });
            });
            form.render();

            $("#her").click(function () {

                var num = $("#tid").val();

                table.reload('listReloadas', {
                    url: '/getonesigner'
                    , method: 'post'
                    , where: {
                        check_waybill_consign_num: num
                    } //设定异步数据接口的额外参数
                    //,height: 300
                });

            });

            table.on('tool(userTable)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

                var id = obj.data.check_id;
                var num = obj.data.check_waybill_consign_num;
                if (layEvent === 'del') { //删除
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            type: "post",
                            url: '../deletesigner',
                            data: {
                                check_id: id,
                                check_waybill_consign_num: num

                            },
                            dataType: "text",
                            success: function (date) {
                                //obj.del(); //删除对应行（tr）的DOM结构，并更新缓存

                                sellsigner();
                            }

                        });
                        layer.close(index);
                        //向服务端发送删除指令
                    });
                }
            });
        })
    });
    $(".list-check > .layui-nav-child > dd > a.nav-signfor-sequ").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAdddeliverylist .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            laydate.render({
                elem: '#CheckOrderdate1'

            });
            layui.use('form', function () {
                var form = layui.form;
                var ids = ['1', '2'];
                var names = ['是', '否'];
                var select = document.getElementById('RiverTypeLevel');
                for (var i = 0; i < ids.length; i++) {
                    var option = document.createElement("option");
                    option.setAttribute("value", ids[i]);
                    option.innerText = names[i];
                    select.appendChild(option)
                }
                form.render("select");
            });

            table.render({
                elem: '#userTables'
                , height: 430
                , url: '../selectsignerlist' //数据接口
                , id: 'listReloadis' //初始化标识id
                , toolbar: "#toolBar"//显示左侧工具栏
                , cols: [[ //表头
                    {type: 'checkbox', sort: true, fixed: 'left'},
                    {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                    {
                        field: 'waybill_consign_date',
                        title: '托运日期',
                        width: 200,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillConsignDate}}</div>'
                    },
                    {title: '核对时间', width: 100, align: 'center', field: 'check_date'},
                    {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                    {
                        title: '交货日期',
                        width: 120,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillPromiseDate}}</div>'
                    },
                    {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                            if (d.track.trackType =='2'){
                                return '准备装车'
                            }else if(d.track.trackType =='3'){
                                return '已装车'
                            }else if(d.track.trackType =='1'){
                                return '发站库存'
                            }else if(d.track.trackType =='4'){
                                return '运输途中'
                            }else if(d.track.trackType =='5'){
                                return '到站库存'
                            }else if(d.track.trackType =='6'){
                                return '派送中'
                            }else if(d.track.trackType =='7'){
                                return '已签收'
                            }
                        }},
                    {title: '运输类型', width: 80, align: 'center', templet: '<div>{{d.waybill.waybillTransType}}</div>'},
                    {title: '货物名称', width: 130, align: 'center', templet: '<div>{{d.waybill.waybillCargoName}}</div>'},
                    {title: '总数量', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillCargoCount}}</div>'},
                    {field: 'check_sign_count', title: '核对数', width: 160, align: 'center'},
                    {title: '包装', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillPackingWay}}</div>'},
                    {title: '总数量', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillCargoCount}}</div>'},
                    {title: '发货单位', width: 160, align: 'center', templet: '<div>{{d.shipper.shipperCom}}</div>'},
                    {title: '收货单位', width: 160, align: 'center', templet: '<div>{{d.consignee.consiCom}}</div>'},
                    {title: '收货人', width: 160, align: 'center', templet: '<div>{{d.consignee.consiPerson}}</div>'},
                    {title: '收货人电话', width: 160, align: 'center', templet: '<div>{{d.consignee.consiTelephone}}</div>'},
                    {title: '收货地址', width: 160, align: 'center', templet: '<div>{{d.consignee.consiAddress}}</div>'},
                    {title: '核对状态', width: 100, align: 'center', field: 'check_car_loading'},
                    {title: '备注', width: 160, align: 'center', templet: '<div>{{d.waybill.waybillRemark}}</div>'},
                ]]
                ,done: function (res, curr, count) {
                    var that = this.elem.next();
                    res.data.forEach(function (item, index) {
                        if (item.check_car_loading === "是") {
                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                            tr.css("background-color", "block");
                            tr.css("color", "red");
                        }
                    });
                }

            })

            table.on('toolbar(userTables)', function (obj) {
                switch (obj.event) {
                    case 'insert':
                        opetitle = "添加";
                        break;
                    case 'update':
                        opetitle = "核对";
                        updateData(obj);
                        break;
                    case 'delete':
                        break;
                    default:
                        break;
                }
            });


            function updateData(obj) {
                layui.use(['layer', 'table', 'jquery'], function () {
                    var layer = layui.layer;
                    var table = layui.table;
                    var $ = layui.jquery;
                    layer.open({
                        title: opetitle,
                        content: '测试回调',
                        //大小
                        area: ['300px', '180px'],
                        btn: ['确定', '取消'],
                        content: '是否确定要核对选中行?',
                        yes: function (index, kskks) {
                            //获取复选框选中行，checkStatus
                            var checkStatus = table.checkStatus(obj.config.id);
                            //获取复选框选中行对象
                            var data = checkStatus.data;
                            var ids = [];
                            //因为是json格式所以循环
                            for (var i = 0; i < data.length; i++) {
                                // 将选中的行保存到数组
                                ids.push(data[i].check_id);
                            }
                            $.ajax({
                                url: '../updateload',
                                type: 'post',
                                dataType: 'text',
                                data: {

                                    ids: ids.join(',')
                                },
                                success: function (data) {
                                    table.render({
                                        elem: '#userTables'
                                        , height: 430
                                        , url: '../selectsignerlist' //数据接口
                                        , id: 'listReloadis' //初始化标识id
                                        , toolbar: "#toolBar"//显示左侧工具栏
                                        , cols: [[ //表头
                                            {type: 'checkbox', fixed: 'left'},
                                            {
                                                field: 'check_waybill_consign_num',
                                                title: '托运单号',
                                                width: 80,
                                                align: 'center'

                                            },
                                            {
                                                field: 'waybill_consign_date',
                                                title: '托运日期',
                                                width: 200,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillConsignDate}}</div>'

                                            },
                                            {title: '核对时间', width: 100, align: 'center', field: 'check_date'},
                                            {
                                                title: '到达城市',
                                                width: 100,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillReachCity}}</div>'

                                            },
                                            {
                                                title: '交货日期',
                                                width: 120,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillPromiseDate}}</div>'

                                            },
                                            {
                                                title: '运单状态',
                                                width: 100,
                                                align: 'center',
                                                templet: '<div>{{d.track.trackType}}</div>'
                                                ,templet: function (d) {
                                                    if (d.track.trackType =='2'){
                                                        return '准备装车'
                                                    }else if(d.track.trackType =='3'){
                                                        return '已装车'
                                                    }else if(d.track.trackType =='1'){
                                                        return '发站库存'
                                                    }else if(d.track.trackType =='4'){
                                                        return '运输途中'
                                                    }else if(d.track.trackType =='5'){
                                                        return '到站库存'
                                                    }else if(d.track.trackType =='6'){
                                                        return '派送中'
                                                    }else if(d.track.trackType =='7'){
                                                        return '已签收'
                                                    }
                                                }
                                            },
                                            {
                                                title: '运输类型',
                                                width: 80,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillTransType}}</div>'

                                            },
                                            {
                                                title: '货物名称',
                                                width: 130,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoName}}</div>'

                                            },
                                            {
                                                title: '总数量',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoCount}}</div>'

                                            },
                                            {field: 'check_sign_count', title: '核对数', width: 160, align: 'center'},

                                            {
                                                title: '包装',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillPackingWay}}</div>'

                                            },
                                            {
                                                title: '总数量',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillCargoCount}}</div>'

                                            },
                                            {
                                                title: '发货单位',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.shipper.shipperCom}}</div>'

                                            },
                                            {
                                                title: '收货单位',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiCom}}</div>'

                                            },
                                            {
                                                title: '收货人',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiPerson}}</div>'

                                            },
                                            {
                                                title: '收货人电话',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiTelephone}}</div>'

                                            },
                                            {
                                                title: '收货地址',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.consignee.consiAddress}}</div>'

                                            },
                                            {title: '核对状态', width: 100, align: 'center', field: 'check_car_loading'},
                                            {
                                                title: '备注',
                                                width: 160,
                                                align: 'center',
                                                templet: '<div>{{d.waybill.waybillRemark}}</div>'

                                            },
                                        ]]
                                        ,done: function (res, curr, count) {
                                            var that = this.elem.next();
                                            res.data.forEach(function (item, index) {
                                                if (item.check_car_loading === "是") {
                                                    var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                                                    tr.css("background-color", "block");
                                                    tr.css("color", "red");
                                                }
                                            });
                                        }
                                    })

                                    layer.close(index);
                                }
                            });
                        }
                    });
                });

            }

            $("#btnaddgzss").click(function () {

                var num = $("#TransportOrderID").val();
                var num1 = $("select#RiverTypeLevel + .layui-form-select dl dd.layui-this").text();
                var num2 = $("#ShipmentsCompany").val();
                var num3 = $("#CheckOrderdate1").val();
                var num4 = $("#ComeCity").val();

                console.log("num1");
                table.reload('listReloadis', {
                    url: '/selectallyuju3'
                    , method: 'post'
                    , where: {
                        check_waybill_consign_num: num,
                        check_car_loading: num1,
                        shipper_com: num2,
                        check_date: num3,
                        waybill_reach_city: num4
                    } //设定异步数据接口的额外参数
                    //,height: 30

                });

            });
        })
    });

    function sellsigner() {
        //第一个实例
        table.render({
            elem: '#userTable'
            , height: 430
            , url: '../getAllsigner' //数据接口
            , id: 'listReloadas' //初始化标识id
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                {field: 'check_date', title: '提交日期', width: 200, align: 'center'},
                {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                        if (d.track.trackType =='2'){
                            return '准备装车'
                        }else if(d.track.trackType =='3'){
                            return '已装车'
                        }else if(d.track.trackType =='1'){
                            return '发站库存'
                        }else if(d.track.trackType =='4'){
                            return '运输途中'
                        }else if(d.track.trackType =='5'){
                            return '到站库存'
                        }else if(d.track.trackType =='6'){
                            return '派送中'
                        }else if(d.track.trackType =='7'){
                            return '已签收'
                        }
                    }},
                {
                    field: 'waybill.waybill_cargo_name',
                    title: '货名',
                    width: 120,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillCargoName}}</div>'
                },
                {
                    field: 'waybill.waybill_cargo_count',
                    title: '总数量',
                    width: 100,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillCargoCount}}</div>'
                },
                {field: 'check_sign_count', title: '核对数', width: 80, align: 'center'},
                {field: 'check_car_loading', title: '核对状态', width: 130, align: 'center'},
                {

                    title: '到达分站',
                    width: 160,
                    align: 'center',
                    templet: '<div>{{d.subst.substName}}</div>'
                },
                {
                    field: 'waybill.waybill_billing_person',
                    title: '录入员',
                    width: 160,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillPromoter}}</div>'
                },
                {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}
            ]]

        })

    }
    function selldeliver() {
        //第一个实例
        table.render({
            elem: '#userTable'
            , height: 430
            , url: '../getAlldelivery' //数据接口
            , id: 'listReloadssse' //初始化标识id
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                {field: 'check_date', title: '提交日期', width: 200, align: 'center'},
                {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                        if (d.track.trackType =='2'){
                            return '准备装车'
                        }else if(d.track.trackType =='3'){
                            return '已装车'
                        }else if(d.track.trackType =='1'){
                            return '发站库存'
                        }else if(d.track.trackType =='4'){
                            return '运输途中'
                        }else if(d.track.trackType =='5'){
                            return '到站库存'
                        }else if(d.track.trackType =='6'){
                            return '派送中'
                        }else if(d.track.trackType =='7'){
                            return '已签收'
                        }
                    }},
                {
                    field: 'waybill.waybill_cargo_name',
                    title: '货名',
                    width: 120,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillCargoName}}</div>'
                },
                {
                    field: 'waybill.waybill_cargo_count',
                    title: '总数量',
                    width: 100,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillCargoCount}}</div>'
                },
                {field: 'check_delivery_count', title: '核对数', width: 80, align: 'center'},
                {field: 'check_car_loading', title: '核对状态', width: 130, align: 'center'},
                {

                    title: '到达分站',
                    width: 160,
                    align: 'center',
                    templet: '<div>{{d.subst.substName}}</div>'
                },
                {
                    field: 'waybill.waybill_billing_person',
                    title: '录入员',
                    width: 160,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillPromoter}}</div>'
                },
                {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}
            ]]

        })

    }
    function sellalles() {
        //第一个实例
        table.render({
            elem: '#userTable'
            , height: 430
            , url: '../getunloadCheck' //数据接口
            , id: 'listReloadsss' //初始化标识id
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                {field: 'check_date', title: '提交日期', width: 200, align: 'center'},
                {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                        if (d.track.trackType =='2'){
                            return '准备装车'
                        }else if(d.track.trackType =='3'){
                            return '已装车'
                        }else if(d.track.trackType =='1'){
                            return '发站库存'
                        }else if(d.track.trackType =='4'){
                            return '运输途中'
                        }else if(d.track.trackType =='5'){
                            return '到站库存'
                        }else if(d.track.trackType =='6'){
                            return '派送中'
                        }else if(d.track.trackType =='7'){
                            return '已签收'
                        }
                    }},
                {
                    field: 'waybill.waybill_cargo_name',
                    title: '货名',
                    width: 120,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillCargoName}}</div>'
                },
                {
                    field: 'waybill.waybill_cargo_count',
                    title: '总数量',
                    width: 100,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillCargoCount}}</div>'
                },
                {field: 'check_unload_count', title: '核对数', width: 80, align: 'center'},
                {field: 'check_car_loading', title: '核对状态', width: 130, align: 'center'},
                {

                    title: '到达分站',
                    width: 160,
                    align: 'center',
                    templet: '<div>{{d.subst.substName}}</div>'
                },
                {
                    field: 'waybill.waybill_billing_person',
                    title: '录入员',
                    width: 160,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillPromoter}}</div>'
                },
                {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}
            ]]

        })

    }
    function sellall() {
        //第一个实例
        table.render({
            elem: '#userTable'
            , height: 430
            , url: '../selectall' //数据接口
            , id: 'listReload' //初始化标识id
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'check_waybill_consign_num', title: '托运单号', width: 80, align: 'center'},
                {field: 'check_date', title: '提交日期', width: 200, align: 'center'},
                {title: '到达城市', width: 100, align: 'center', templet: '<div>{{d.waybill.waybillReachCity}}</div>'},
                {title: '运单状态', width: 100, align: 'center', templet: '<div>{{d.track.trackType}}</div>',templet: function (d) {
                        if (d.track.trackType =='2'){
                            return '准备装车'
                        }else if(d.track.trackType =='3'){
                            return '已装车'
                        }else if(d.track.trackType =='1'){
                            return '发站库存'
                        }else if(d.track.trackType =='4'){
                            return '运输途中'
                        }else if(d.track.trackType =='5'){
                            return '到站库存'
                        }else if(d.track.trackType =='6'){
                            return '派送中'
                        }else if(d.track.trackType =='7'){
                            return '已签收'
                        }
                    }},
                {
                    field: 'waybill.waybill_cargo_name',
                    title: '货名',
                    width: 120,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillCargoName}}</div>'
                },
                {
                    field: 'waybill.waybill_cargo_count',
                    title: '总数量',
                    width: 100,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillCargoCount}}</div>'
                },
                {field: 'check_load_count', title: '核对数', width: 80, align: 'center'},
                {field: 'check_car_loading', title: '核对状态', width: 130, align: 'center'},
                {
                    field: 'waybill.waybill_subst_id',
                    title: '到达分站',
                    width: 160,
                    align: 'center',
                    templet: '<div>{{d.subst.substName}}</div>'
                },
                {
                    field: 'waybill.waybill_billing_person',
                    title: '录入员',
                    width: 160,
                    align: 'center',
                    templet: '<div>{{d.waybill.waybillPromoter}}</div>'
                },
                {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}
            ]]

        })

    }
    $(".list-kpi > .layui-nav-child > dd > a.nav-finance-profit").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAddfinance .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            laydate.render({
                elem: '#starttime'
                , type: 'datetime'
            });
            laydate.render({
                elem: '#endtime'
                , type: 'datetime'
            });
            $("#see").click(function () {

                $.ajax({
                    type: "post",
                    url: '../financecount',
                    data: {
                        waybill_consign_date: $("#starttime").val(),
                        waybill_promise_date: $("#endtime").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        console.log(data);

                        $("#CountOrder").text(data);
                    }
                });
                $.ajax({
                    type: "post",
                    url: '../Waybillincome',
                    data: {
                        waybill_consign_date: $("#starttime").val(),
                        waybill_promise_date: $("#endtime").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        console.log(data);

                        $("#TotalMoney").text(data);
                    }
                });
                $.ajax({
                    type: "post",
                    url: '../rebatecollection',
                    data: {
                        waybill_consign_date: $("#starttime").val(),
                        waybill_promise_date: $("#endtime").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        console.log(data);

                        $("#Rebate").text(data);
                    }
                });
                $.ajax({
                    type: "post",
                    url: '../pickupfee',
                    data: {
                        waybill_consign_date: $("#starttime").val(),
                        waybill_promise_date: $("#endtime").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        console.log(data);

                        $("#PickUpSpend").text(data);
                    }
                });
                $.ajax({
                    type: "post",
                    url: '../transportcount',
                    data: {
                        trans_depart_date: $("#starttime").val(),
                        trans_promise_date: $("#endtime").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        console.log(data);

                        $("#CountTransportNumber").text(data);
                    }
                });
                $.ajax({
                    type: "post",
                    url: '../transporttotal',
                    data: {
                        trans_depart_date: $("#starttime").val(),
                        trans_promise_date: $("#endtime").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        console.log(data);

                        $("#AllPay").text(data);
                    }
                });
                $.ajax({
                    type: "post",
                    url: '../sendtcount',
                    data: {
                        trans_depart_date: $("#starttime").val(),
                        trans_promise_date: $("#endtime").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        console.log(data);

                        $("#CountSendNum").text(data);
                    }
                });
                $.ajax({
                    type: "post",
                    url: '../sendttotal',
                    data: {
                        trans_depart_date: $("#starttime").val(),
                        trans_promise_date: $("#endtime").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        console.log(data);

                        $("#SendMoney").text(data);
                    }
                });
                $.ajax({
                    type: "post",
                    url: '../grosstotal',
                    data: {
                        trans_depart_date: $("#starttime").val(),
                        trans_promise_date: $("#endtime").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        console.log(data);

                        $("#maoli").text(data);
                    }
                });
            });


        })
    });

    $(".list-kpi > .layui-nav-child > dd > a.nav-waybill-indicator").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAddwaybilltarget .page-wrap", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            layui.use('form', function () {
                var form = layui.form;
                var ids = ['1', '2','3','4','5','6'];
                var names = ['发站库存', '已装车','运输途中','到站库存','派送中','已签收'];
                var select = document.getElementById('condition');
                for (var i = 0; i < ids.length; i++) {
                    var option = document.createElement("option");
                    option.setAttribute("value", ids[i]);
                    option.innerText = names[i];
                    select.appendChild(option)
                }
                form.render("select");
            });
            layui.use('form', function () {
                var form = layui.form;
                var ids = ['1', '2','3','4','5'];
                var names = ['超时', '改单','作费','费用异常','货损'];
                var select = document.getElementById('abnormal');
                for (var i = 0; i < ids.length; i++) {
                    var option = document.createElement("option");
                    option.setAttribute("value", ids[i]);
                    option.innerText = names[i];
                    select.appendChild(option)
                }
                form.render("select");
            });
            table.render({
                elem: '#userTableis'
                , height: 430
                , url: '../selectindicator' //数据接口
                , id: 'listRe' //初始化标识id
                , cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'waybillConsignNum', title: '托运单号', width: 80, align: 'center'},
                    {field: 'waybillIncomeTotal', title: '收入合计', width: 200, align: 'center'},
                    {title: '代收支出', width: 100, align: 'center',field: 'waybillRebateCollection'},
                    {title: '提货开支', width: 100, align: 'center',field: 'waybillPickupFee'},
                    {
                        field: 'waybill.waybill_cargo_name',
                        title: '货名',
                        width: 120,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_cargo_count',
                        title: '总数量',
                        width: 100,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillCargoCount}}</div>'
                    },
                    {field: 'check_load_count', title: '核对数', width: 80, align: 'center'},
                    {field: 'check_car_loading', title: '核对状态', width: 130, align: 'center'},
                    {
                        field: 'waybill.waybill_subst_id',
                        title: '到达分站',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.subst.substName}}</div>'
                    },
                    {
                        field: 'waybill.waybill_billing_person',
                        title: '录入员',
                        width: 160,
                        align: 'center',
                        templet: '<div>{{d.waybill.waybillPromoter}}</div>'
                    },
                    {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}
                ]]

            })
        })
    });
    /****************************运单管理模块********************************/
    /*新增运单*/
    $(".list-waybill > .layui-nav-child > dd > a.nav-add-waybill").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAddwaybill .page-this", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }

            //加载页面功能
            addWaybill.initPage();
            addWaybill.bindEvent();


            //表单的监听提交,新增运单
            form.on('submit(saveWaybill)', function (data) {
                var waybillData = data.field;
                console.log(data.field);

                var index = layer.load(1, {
                    shade: [0.3, '#fff'], //0.1透明度的白色背景
                });

                $.ajax({
                    type: "POST",
                    contentType: "application/json;charset=UTF-8",
                    url: "/addWaybill",
                    dataType: "json",
                    data: JSON.stringify(data.field),
                    success: function (data) {
                        console.log(data);
                        layer.close(index);
                        layer.msg(data['msg'], {icon: 6, time: 1400});
                        if (data['result'] == "success") {

                        } else {

                        }
                    }
                });

                return false;
            });
            form.render();

        });
    });

    /*运单列表*/
    $(".list-waybill > .layui-nav-child > dd > a.nav-waybill-list").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/waybillList .page-this", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            laydate.render({ //起止日期，日期下拉框
                elem: '#start-end-date'
                , range: '~' //或 range: '~' 来自定义分割字符
                , theme: "#5974d9"
            });
            //加载分站下拉框
            loadSubstList(["waybillStartingSubst", "waybillReachSubst"]);
            //表单的监听提交，运单搜索
            form.on('submit(waybill-search)', function (data) {
                if (data.field['startEndDate'] != "") {
                    var startEndDate = data.field['startEndDate'];
                    var startEndDateArr = startEndDate.split("~");
                    var startDate = startEndDateArr[0].trim();
                    var endDate = startEndDateArr[1].trim();
                    data.field['startDate'] = startDate;
                    data.field['endDate'] = endDate;
                }

                var trackTypes = [];
                var trackTypeCheckbox = $("input:checked[name='trackTypes']");
                for (var i = 0; i < trackTypeCheckbox.length; i++) {
                    trackTypes.push($(trackTypeCheckbox[i]).val());
                }

                data.field['startEndDate'] = undefined;
                data.field['trackTypes'] = undefined;


                data.field['page'] = waybillTable['config']['page']['curr'];
                data.field['count'] = waybillTable['config']['page']['count'];

                table.reload('waybill-info', {
                    method: "post"
                    , url: "queryWaybillConditionLayui"
                    , where: {
                        waybillCondition: JSON.stringify(data.field),
                        trackTypes: JSON.stringify(trackTypes)
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                return false;
            });
            form.render();

            //运单表格实例
            var waybillTable = table.render({
                elem: '#waybill-info'
                , id: "waybill-info"
                , height: 400
                , url: '/queryWaybillLimitLayui' //数据接口
                , request: {
                    pageName: 'page' //页码的参数名称，默认：page
                    , limitName: 'limit' //每页数据量的参数名，默认：limit
                }
                , page: true //开启分页
                , cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'}
                    , {type: 'numbers', title: "序号"}
                    , {field: 'waybillConsignNum', title: '托运单号', width: 220, sort: true}
                    , {field: 'waybillConsignDate', title: '托运日期', width: 120}
                    , {field: 'shipperCom', title: '发货单位', width: 170}
                    , {field: 'startingSubst', title: '出发分站', width: 170}
                    , {field: 'reachSubst', title: '到达分站', width: 170, sort: true}
                    , {field: 'waybillReachCity', title: '到达城市', width: 170}
                    , {field: 'trackType', title: '运单状态', width: 135,
                        templet:function (d) {
                            var trackType = d.trackType;
                            var content = "";
                            switch (trackType) {
                                case 1:
                                    content = "收件入库";
                                    break;
                                case 2:
                                    content = "准备装车";
                                    break;
                                case 3:
                                    content = "已装车";
                                    break;
                                case 4:
                                    content = "正在运输";
                                    break;
                                case 5:
                                    content = "转运";
                                    break;
                                case 6:
                                    content = "正在派送";
                                    break;
                                case 7:
                                    content = "已签收";
                            }
                            return content;
                        }
                    }
                    , {field: 'waybillTransType', title: '运输类型', width: 135, sort: true}
                    , {field: 'waybillCargoName', title: '货物名称', width: 135, sort: true}
                    , {field: 'waybillPromiseDate', title: '承诺时间', width: 135, sort: true}
                    , {field: 'trackDate', title: '签收时间', width: 135, sort: true}
                    , {field: 'waybillCargoCount', title: '数量', width: 135, sort: true}
                    , {field: 'waybillPackingWay', title: '包装', width: 135, sort: true}
                    , {field: 'waybillCargoWeight', title: '重量/kg', width: 135, sort: true}
                    , {field: 'waybillCargoVolume', title: '体积/m³', width: 135, sort: true}
                    , {field: 'waybillCargoPrice', title: '单价', width: 135, sort: true}
                    , {field: 'waybillBasicFreight', title: '基本运费', width: 135, sort: true}
                    , {field: 'waybillPickupFee', title: '提货费', width: 135, sort: true}
                    , {field: 'waybillDeliveryFee', title: '送货费', width: 135, sort: true}
                    , {field: 'waybillCargoValue', title: '货物价值', width: 135, sort: true}
                    , {field: 'waybillInsuranceFee', title: '保费', width: 135, sort: true}
                    , {field: 'waybillIncomeTotal', title: '费用合计', width: 135, sort: true}
                    , {field: 'waybillNowIncome', title: '现付', width: 135, sort: true}
                    , {field: 'waybillPaymentMethod', title: '付款方式', width: 135, sort: true}
                    , {field: 'waybillReachPay', title: '到付', width: 135, sort: true}
                    , {
                        title: '到付状态', width: 135, sort: true
                        , templet: function (d) {
                            return d.waybillReachPay ? '未付' : '';
                        }
                    }
                    , {field: 'waybillBackpayMonth', title: '回付', width: 135, sort: true}
                    , {
                        title: '回付状态', width: 135, sort: true
                        , templet: function (d) {
                            return d.waybillBackpayMonth ? '未付' : '';
                        }
                    }
                    , {field: 'shipperPerson', title: '发货人', width: 135, sort: true}
                    , {field: 'shipperTelephone', title: '发货电话', width: 135, sort: true}
                    , {field: 'shipperAddress', title: '发货地址', width: 170, sort: true}
                    , {field: 'consiCom', title: '收货单位', width: 170, sort: true}
                    , {field: 'consiPerson', title: '收货人', width: 135, sort: true}
                    , {field: 'consiTelephone', title: '电话', width: 135, sort: true}
                    , {field: 'consiAddress', title: '收货地址', width: 135, sort: true}
                    , {field: 'consiRemark', title: '备注', width: 135, sort: true}
                    , {field: 'carloadTransNum', title: '运输单号', width: 135, sort: true}
                    , {field: 'carloadCarNum', title: '运输车号', width: 135, sort: true}
                    , {field: 'carDriver', title: '司机姓名', width: 135, sort: true}
                    , {field: 'carDriverPhone', title: '司机手机', width: 135, sort: true}
                    , {field: 'waybillPromoter', title: '业务员', width: 135, sort: true}
                    , {field: 'empName', title: '开单员', width: 135, sort: true}
                ]]
            });


            /*运单作废*/
            $(".waybill-list-btn-group .delete-waybill").click(function () {
                var checkStatus = table.checkStatus('waybill-info');//获取数据表格的选中状态

                var waybillConsignNumS = [];
                for (var i = 0; i < checkStatus.data.length; i++) {
                    waybillConsignNumS.push(checkStatus.data[i]['waybillConsignNum']);
                }

                console.log(checkStatus);
                if (checkStatus.data.length == 0) {
                    layer.msg('请先选中需要取消的运单！', {
                        anim: 6
                        , time: 2000
                    });
                } else {
                    layer.open({
                        type: 0,
                        title: "温馨提示",
                        content: "您确定要取消所选的运单吗？",
                        btn: ['确定','取消'],
                        yes:function(){
                            var index = layer.load(1, {
                                shade: [0.3, '#fff'], //0.1透明度的白色背景
                            });

                            //根据托运单号删除对应运单信息
                            $.ajax({
                                url: "/cancelWaybillByConsignNumS",
                                contentType: "application/json;charset=UTF-8",
                                type: "POST",
                                dataType: "json",
                                data: JSON.stringify(waybillConsignNumS),
                                success: function (data) {
                                    console.log(data);
                                    layer.close(index);
                                    if (data['result'] == "success") {
                                        layer.msg(data['msg'], {icon: 6, time: 2000});
                                        table.reload('waybill-info');
                                    } else {
                                        layer.msg(data['msg'], {icon: 0, time: 2000});
                                    }

                                }
                            });
                        }
                    });
                }

            });


            /*修改运单*/
            $(".waybill-list-btn-group .update-waybill").click(function () {
                var checkStatus = table.checkStatus('waybill-info');//获取数据表格的选中状态
                if (checkStatus.data.length == 0) {
                    layer.msg('请先选中需要修改的运单！', {
                        anim: 6
                        , time: 2000
                    });
                } else if (checkStatus.data.length > 1) {
                    layer.msg('只能选择一个运单修改！', {
                        anim: 6
                        , time: 2000
                    });
                } else {
                    //根据托运单号查询对应运单信息
                    $.ajax({
                        url: "/queryWaybillById",
                        type: "POST",
                        data: {
                            waybillConsignNum: checkStatus.data[0]['waybillConsignNum']
                        },
                        success: function (data) {
                            console.log(data);
                            $(".page > .page-wrap").children().remove();
                            $(".page > .page-wrap").load("/goUpdatewaybill .page-this-updatewaybill", function () {

                                //加载页面功能
                                addWaybill.initPage(data['waybillChargeMode'],data['waybillPaymentMethod']);
                                loadCarDriverList(data['waybillStartingSubst']);
                                layer.load(1, {
                                    shade: [0.3, '#fff'], //0.1透明度的白色背景
                                    time: 1000,
                                    end: function () {
                                        form.val("update-waybill-form", {
                                            waybillBackpayMonth: data['waybillBackpayMonth'],
                                            waybillBasicFreight: data['waybillBasicFreight'],
                                            waybillBillingPerson: data['waybillBillingPerson'],
                                            waybillCargoCount: data['waybillCargoCount'],
                                            waybillCargoName: data['waybillCargoName'],
                                            waybillCargoPrice: data['waybillCargoPrice'],
                                            waybillCargoValue: data['waybillCargoValue'],
                                            waybillCargoVolume: data['waybillCargoVolume'],
                                            waybillCargoWeight: data['waybillCargoWeight'],
                                            waybillChargeMode: data['waybillChargeMode'],
                                            waybillConsiId: data['waybillConsiId'],
                                            waybillConsignDate: data['waybillConsignDate'],
                                            waybillConsignNum: data['waybillConsignNum'],
                                            waybillDeliveryFee: data['waybillDeliveryFee'],
                                            waybillIncomeTotal: data['waybillIncomeTotal'],
                                            waybillInsuranceFee: data['waybillInsuranceFee'],
                                            waybillNowIncome: data['waybillNowIncome'],
                                            waybillOrderNum: data['waybillOrderNum'],
                                            waybillOther: data['waybillOther'],
                                            waybillPackingWay: data['waybillPackingWay'],
                                            waybillPaymentMethod: data['waybillPaymentMethod'],
                                            waybillPickupDriver: data['waybillPickupDriver'],
                                            waybillPickupFee: data['waybillPickupFee'],
                                            waybillPickupSpend: data['waybillPickupSpend'],
                                            waybillPromiseDate: data['waybillPromiseDate'],
                                            waybillPromoter: data['waybillPromoter'],
                                            waybillReachCity: data['waybillReachCity'],
                                            waybillReachPay: data['waybillReachPay'],
                                            waybillReachSubst: data['waybillReachSubst'],
                                            waybillRebateCollection: data['waybillRebateCollection'],
                                            waybillReceipt: data['waybillReceipt'],
                                            waybillRemark: data['waybillRemark'],
                                            waybillShipperId: data['waybillShipperId'],
                                            waybillShippingMethod: data['waybillShippingMethod'],
                                            waybillSignforMess: data['waybillSignforMess'],
                                            waybillStartingSubst: data['waybillStartingSubst'],
                                            waybillTransType: data['waybillTransType'],
                                            waybillUploadFee: data['waybillUploadFee']
                                        });
                                        addWaybill.bindEvent();


                                        form.on('submit(saveUpdateWaybill)', function (data) {
                                            console.log(data.field);

                                            $.ajax({
                                                type: "POST",
                                                contentType: "application/json;charset=UTF-8",
                                                url: "/updateWaybill",
                                                dataType: "json",
                                                data: JSON.stringify(data.field),
                                                success: function (data) {
                                                    console.log(data);
                                                    layer.msg(data['msg'], {icon: 6, time: 1400});
                                                    if (data['result'] == "success") {

                                                    } else {

                                                    }
                                                }
                                            });

                                            return false;
                                        });
                                        form.render();
                                    }
                                });
                            });


                        }
                    });
                }
            });


            //查看运单详情页面
            table.on('rowDouble(waybill-info)', function (obj) {
                var data = obj.data;
                $(".page > .page-wrap").children().remove();
                $(".page > .page-wrap").load("/waybilldetail .page-this", function () {

                });
            });

        });
    });


    /********************************************运输管理模块************************************************************/
    /*运输管理*/
    /*装车配载*/
    $(".list-trans >.layui-nav-child > dd > a.nav-carload").click(function () {
        function loading(){
            //筛选查询
            $('#find').on('click', function(){

                //substr 方法用于返回一个从指定位置开始的指定长度的子字符串
                var Date1 =  $("#startdate").val().substr(0,10);
                var Date2 = $("#startdate").val().substr(12,22);
                //执行重载
                table.reload('demoone', {
                    method:"post"
                    ,url:"getAll"
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        waybillConsignNum: $("#TransportOrderID").val(),
                        waybillStartingSubst: $("#StartStation").val(),
                        waybillReachSubst :  $("#ComeStation").val(),
                        waybillConsignDate: Date1,
                        waybillPromiseDate: Date2,
                        waybillTransType:$("#FreightType").val()
                    }
                });
            });


            //查询分站
            $.ajax({
                type: 'post',

                url: '/subtype',

                dataType: 'json',

                success: function (data) {
                    //添加select第一个option
                    $("#ComeStation").append("<option selected value=''>请选择</option>");
                    for (var i = 0; i < data.length; i++) {
                        //添加option元素
                        $("#ComeStation").append("<option value='" + data[i].substId + "'>" + data[i].substName + "</option>");
                    }
                    form.render();
                }, error: function (data) {
                    layer.msg('系统错误', {icon: 6, time: 1400});
                }

            });
            //查询出发地
            $.ajax({
                type: 'post',

                url: '/subtype',

                dataType: 'json',

                success: function (data) {
                    //添加select第一个option
                    $("#StartStation").append("<option selected value=''>请选择</option>");
                    for (var i = 0; i < data.length; i++) {
                        //添加option元素
                        $("#StartStation").append("<option value='" + data[i].substId + "'>"+ data[i].substName +"</option>");
                    }
                    form.render();
                }, error: function (data) {
                    layer.msg('系统错误', {icon: 6, time: 1400});
                }

            });

            //添加模拟装车
            $("#btnrightadd").click(function () {
                if($("#txtTransportOrderID").val()!=""){
                    var val = $("#txtTransportOrderID").val();
                    var index = layer.load(1, {
                        shade: [0.3, '#fff'], //0.1透明度的白色背景
                    });
                    $.ajax({
                        type: 'post',

                        url: '/changeStatetwo',
                        dataType: 'json',
                        data: {id:$("#txtTransportOrderID").val()},
                        success: function (data) {
                            layer.close(index);
                            if(data==1){
                                table.reload('demoone',{});
                                table.reload('demotwo',{});
                            }else {
                                layer.msg('库存没有该运单,或者早已进行该阶段', {icon: 6, time: 1400});
                            }
                        }, error: function (data) {
                            layer.msg('系统错误', {icon: 6, time: 1400});

                        }
                    });
                    //执行重载
                    table.reload('demotwo', {
                    });
                } else if($("#txtTransportOrderID").val()==""){
                    layer.msg('请输入单号', {icon: 6, time: 1400});
                }else{
                    layer.msg(val +'不是匹配值', {icon: 6, time: 1400});
                }

            });


            //添加装车表
            $("#btnmove").click(function () {
                var checkStatus = table.checkStatus('demoone');
                var data = checkStatus.data;
                if (data.length==0){
                    layer.msg('请至少选中一行', {
                        time: 1000, //20s后自动关闭
                    });
                }else if (data.length>=1){
                    var ids = [];
                    //因为是json格式所以循环
                    for(var i = 0;i < data.length;i++){

                        // 将选中的行保存到数组
                        ids.push(data[i].waybillConsignNum);
                    }
                    var index = layer.load(1, {
                        shade: [0.3, '#fff'], //0.1透明度的白色背景
                    });
                    $.ajax({
                        url:'addtruckloading',
                        type:'post',
                        dataType:'json',
                        data:{
                            ids:ids.join(','),
                        },
                        success:function(data){
                            layer.close(index);
                            table.reload('demoone',{});
                            //执行重载
                            table.reload('demotwo', {});
                        }
                    });
                }
            });

            //移除装车
            $("#btntoleft").click(function () {
                var checkStatus = table.checkStatus('demotwo');
                var data = checkStatus.data;
                if (data.length==0){
                    layer.msg('请至少选中一行', {
                        time: 1000, //20s后自动关闭
                    });
                }else if (data.length>=1){
                    var ids = [];
                    //因为是json格式所以循环
                    for(var i = 0;i < data.length;i++){

                        // 将选中的行保存到数组
                        ids.push(data[i].waybillConsignNum);
                    }
                    $.ajax({
                        url:'removecar',
                        type:'post',
                        dataType:'json',
                        data:{
                            ids:ids.join(','),
                        },
                        success:function(data){
                            if (data>=1){
                                table.reload('demoone',{});
                                //执行重载
                                table.reload('demotwo', {
                                });

                            }
                        }
                    });
                }
            })

            //清空列表
            $("#btnrightclear").click(function () {
                var datas = layui.table.cache["demotwo"]
                var ids = [];
                for(var i = 0;i < datas.length;i++){
                    // 将选中的行保存到数组
                    ids.push(datas[i].waybillConsignNum);
                }
                $.ajax({
                    url: 'clearall',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        ids:ids.join(','),
                    },
                    success: function (data) {
                        table.reload('demoone', { })
                        table.reload('demotwo', { })
                    }
                });
            });

            //保存装车
            $("#btnrightsave").click(function () {
                var checkStatus = table.checkStatus('demotwo');
                var data = checkStatus.data;
                if (data.length==0){
                    layer.msg('请至少选中一行', {
                        time: 1000, //20s后自动关闭
                    });
                }else if (data.length>=1){
                    var pand = true;
                    var ids = [];
                    //总件数
                    var sum = 0;
                    //总重量
                    var weight = 0;
                    //总体积
                    var Volume =0;
                    //总运费
                    var Freight=0;
                    //总提车费
                    var Extractfee=0;
                    //总送车费
                    var Sendfare=0;
                    //费用合计
                    var ExpenseTotal=0;
                    //因为是json格式所以循环
                    for(var i = 0;i < data.length;i++){
                        // 将选中的行保存到数组
                        ids.push(data[i].waybillConsignNum);
                        sum = data[i].waybillCargoCount+sum;
                        weight = data[i].waybillCargoWeight+weight;
                        Volume = data[i].waybillCargoVolume+Volume;
                        Freight = data[i].waybillBasicFreight+Freight;
                        Extractfee = data[i].waybillPickupFee+Extractfee;
                        Sendfare = data[i].waybillDeliveryFee+Sendfare;
                        ExpenseTotal = data[i].waybillIncomeTotal+ExpenseTotal;
                        if (data.length>1){
                            var j = i+1;
                            if(j<data.length) {
                                var pand1 = data[i].startingSubst != data[j].startingSubst;
                                var pand1 = data[i].reachSubst != data[j].reachSubst;
                                if(pand1){
                                    pand = false;
                                    layer.msg('请选择相同出发站,到达站的运单', {
                                        time: 1500, //20s后自动关闭
                                    });
                                }
                            }
                        }
                    }
                    if(pand) {
                        var index = layer.load(1, {
                            shade: [0.3, '#fff'], //0.1透明度的白色背景
                        });
                        $.ajax({
                            url: 'savecar',
                            type: 'post',
                            dataType: 'json',
                            data: {
                                ids: ids.join(','),
                                sum: sum,
                                length: data.length,
                                weight: weight,
                                Volume: Volume,
                                Freight: Freight,
                                Extractfee: Extractfee,
                                Sendfare: Sendfare,
                                ExpenseTotal: ExpenseTotal,
                                Starting:data[0].startingSubst
                            },
                            success: function (data) {
                                if (data = 1) {
                                    //保存数据到装车清单表
                                    $.ajax({
                                        url:'relation',
                                        type:'post',
                                        dataType:'json',
                                        data:{
                                            ids:ids.join(','),
                                        },
                                        success:function(data){
                                            layer.close(index);
                                            table.reload('demothree', {});
                                            //执行重载
                                            table.reload('demotwo', {});
                                        }
                                    });

                                }
                            }
                        });
                    }

                }
            })

            //重新装车
            $("#reloading").click(function () {
                var checkStatus = table.checkStatus('demothree');
                var data = checkStatus.data;
                if (data.length==0){
                    layer.msg('请至少选中一行', {
                        time: 1000, //20s后自动关闭
                    });
                }else if(data[0].carloadTransNum!=null&&data[0].carloadCarNum!=null){
                    layer.msg('已开通协议,不能装车', {
                        time: 1000, //20s后自动关闭
                    });
                }else if (data.length>=1){
                    var ids = [];
                    var id = [];
                    //因为是json格式所以循环
                    for(var i = 0;i < data.length;i++){
                        if(data[i].carloadTransNum!=null&&data[i].carloadCarNum!=null){
                            layer.msg(data[i].carloadSeqNum+'已开通运输协议,不能重新装车', {
                                time: 1000, //20s后自动关闭
                            });
                        }else {
                            // 将选中的行保存到数组
                            ids.push(data[i].carloadlist);
                            id.push(data[i].carloadSeqNum);
                        }
                    }
                    var index = layer.load(1, {
                        shade: [0.3, '#fff'], //0.1透明度的白色背景
                    });
                    $.ajax({
                        url:'removecartwo',
                        type:'post',
                        dataType:'json',
                        data:{
                            ids:ids.join(','),
                            id:id.join(',')
                        },
                        success:function(data){
                            if (data=1){
                                //删除装车清单表数据
                                $.ajax({
                                    url:'deleterelation',
                                    type:'post',
                                    dataType:'json',
                                    data:{
                                        id:id.join(',')
                                    },
                                    success:function(data){
                                        layer.close(index);
                                        table.reload('demothree', {});
                                        //执行重载
                                        table.reload('demotwo', {});
                                    }
                                });

                            }
                        }
                    });
                }
            })
            //执行一个laydate实例
            laydate.render({
                elem: '#startdate' //指定元素
                , range: true //或 range: '~' 来自定义分割字符
            });

            //第一个实例
            table.render({
                elem: '#demo'
                ,id:'demoone'
                ,width: 2300
                ,height: 380
                ,url:'getAll'//数据接口
                ,page: true //开启分页
                ,limit:5
                ,limits:[1, 2, 3,4,5]
                ,cols: [[ //表头
                    {type: 'checkbox',fixed: 'left' }
                    ,{field: 'waybillConsignNum', title: '托运单号', width:110, sort: true}
                    ,{field: 'waybillConsignDate', title: '托运日期', width:110}
                    ,{field: 'waybillCargoName', title: '货物名', width: 117}
                    ,{field: 'waybillTransType', title: '运输方式', width: 110, sort: true}
                    ,{field: 'startingSubst',title: '出发站', width: 120, sort: true}
                    ,{field: 'reachSubst',title: '到达分站', width: 110}
                    ,{field: 'waybillReachCity', title: '到达城市', width: 110, sort: true}
                    ,{field: 'shipperCom', title: '发货单位', width: 170, sort: true}
                    ,{field: 'waybillCargoCount', title: '数量', width: 80, sort: true}
                    ,{field: 'waybillPackingWay', title: '包装', width: 80, sort: true}
                    ,{field: 'waybillCargoWeight', title: '重量/KG', width: 135, sort: true}
                    ,{field: 'waybillCargoVolume', title: '总体积/m³', width: 135, sort: true}
                    ,{field: 'waybillBasicFreight', title: '基本运费', width: 135, sort: true}
                    ,{field: 'waybillPickupFee', title: '提货费', width: 135, sort: true}
                    ,{field: 'waybillDeliveryFee', title: '送货费', width: 135, sort: true}
                    ,{field: 'waybillIncomeTotal', title: '费用合计', width: 135, sort: true}
                    ,{field: 'consiAddress', title: '地址', width: 135, sort: true}
                    ,{field: 'waybillRemark', title: '备注', width: 80, sort: true}
                ]]


            });

            //第二个实例
            table.render({
                elem: '#demo1'
                ,width:2900
                ,height: 380
                ,id:'demotwo'
                ,url: '/getAll?status='+2+'' //数据接口
                ,page: true //开启分页
                ,limit:5
                ,limits:[1, 2, 3,4,5]
                ,cols: [[ //表头
                    {type: 'checkbox',fixed: 'left' }
                    ,{field: 'waybillConsignNum', title: '托运单号', width:110, sort: true}
                    ,{field: 'waybillConsignDate', title: '托运日期', width:110}
                    ,{field: 'waybillCargoName', title: '货物名', width: 117}
                    ,{field: 'waybillTransType', title: '运输方式', width: 110, sort: true}
                    ,{field: 'startingSubst', title: '出发站', width: 120, sort: true}
                    ,{field: 'reachSubst',title: '到达分站', width: 110}
                    ,{field: 'waybillReachCity', title: '到达城市', width: 110, sort: true}
                    ,{field: 'waybillCargoCount', title: '数量', width: 80, sort: true}
                    ,{field: 'waybillPackingWay', title: '包装', width: 80, sort: true}
                    ,{field: 'waybillCargoWeight', title: '重量/KG', width: 135, sort: true}
                    ,{field: 'waybillCargoVolume', title: '总体积/m³', width: 135, sort: true}
                    ,{field: 'waybillBasicFreight', title: '基本运费', width: 110, sort: true}
                    ,{field: 'waybillPickupFee', title: '提货费', width: 135, sort: true}
                    ,{field: 'waybillDeliveryFee', title: '送货费', width: 135, sort: true}
                    ,{field: 'waybillIncomeTotal', title: '费用合计', width: 135, sort: true}
                    ,{field: 'waybillRebateCollection', title: '代收', width: 80, sort: true}
                    ,{field: 'waybillReachPay', title: '到付', width: 80, sort: true}
                    ,{field: 'shipperCom', title: '发货单位', width: 150, sort: true}
                    ,{field: 'shipperTelephone', title: '发货电话', width: 130, sort: true}
                    ,{field: 'consiCom', title: '收货单位', width: 170, sort: true}
                    ,{field: 'consiTelephone',title: '收货电话', width: 130, sort: true}
                    ,{field: 'consiAddress', title: '地址', width: 135, sort: true}
                    ,{field: 'waybillRemark', title: '备注', width: 150, sort: true}
                ]]
            });



            //第三个实例
            table.render({
                elem: '#demo2'
                ,id:"demothree"
                ,width:1900
                ,height: 380
                ,url: 'truckloading' //数据接口
                ,page: true //开启分页
                ,limit:5
                ,limits:[1, 2, 3,4,5]
                ,cols: [[ //表头
                    {type: 'checkbox',fixed: 'left' }
                    ,{field: 'carloadSeqNum', title: '装车序号', width:110, sort: true}
                    ,{field: 'carloadTransNum', title: '运输单号', width:150, sort: true}
                    ,{field: 'carloadCarNum', title: '运输车号', width:110}
                    ,{field: 'carloadlist', title: '装车清单', width: 170}
                    ,{field: 'carloadOperator', title: '操作人', width: 150, sort: true}
                    ,{field: 'carloadDate', title: '装车日期', width: 110, sort: true}
                    ,{field: 'carloadWaybillNum', title: '运单数量', width: 110}
                    ,{field: 'carloadStarting',title: '出发站', width: 110, sort: true}
                    ,{field: 'carloadTotalNum', title: '总件数', width: 110, sort: true}
                    ,{field: 'carloadTotalWeight', title: '总重量/KG', width: 120, sort: true}
                    ,{field: 'carloadTotalVolume', title: '总体积/m³', width: 120, sort: true}
                    ,{field: 'carloadTotalFreight', title: '总运费', width: 110, sort: true}
                    ,{field: 'carloadTotalExtractfee', title: '总提车费', width: 110, sort: true}
                    ,{field: 'carloadTotalSendfare', title: '总送车费', width: 110, sort: true}
                    ,{field: 'carloadExpenseTotal', title: '费用合计', width: 110, sort: true}
                ]]
            });
            //input事件
            $("input[type=button]").click(function () {
                var val = $(this).val();
                var checkStatus = table.checkStatus('demothree');
                var data = checkStatus.data;
                if (val == "新增运输协议") {
                    if (data.length==0||data.length!=1){
                        layer.msg('请选中一行', {
                            time: 1000, //20s后自动关闭
                        });
                    }else if(data[0].carloadTransNum!=null&&data[0].carloadCarNum!=null){
                        layer.msg('已开通运输协议', {
                            time: 1000, //20s后自动关闭
                        });
                    }else if (data.length=1){
                        $(".page > .page-wrap").children().remove();
                        $(".page > .page-wrap").load("/addtraprotocol .common-body", function () {
                            form.render();
                            //运费合计
                            $(".num").change(function () {
                                var pand =true;
                                var sum = 0;
                                if ($("#transCashpay").val()!=""&&$("#transBackPay").val()!=""&&$("#transSubstationPay").val()!=""){
                                    for(var i=0;i<$(".num").length;i++){
                                        var b = String($(".num:eq("+i+")").val()).split('');
                                        sum=sum+parseInt($(".num:eq("+i+")").val());
                                        for (var j=0;j<b.length;j++){
                                            if(!isNaN(b[j])){
                                            }else {
                                                pand=false;
                                            }
                                        }
                                    }
                                    if(pand){
                                        $("#transFreightTotal").val(sum);
                                    }else {
                                        layer.msg('请输入正确的金额格式', {icon: 6, time: 1400});
                                    }
                                }

                            })
                            //查询分站
                            $.ajax({
                                type: 'post',

                                url: '/subtype',

                                dataType: 'json',

                                success: function (data) {
                                    //添加select第一个option
                                    $("#transReachSubstation").append("<option selected value=''>请选择</option>");
                                    for (var i = 0; i < data.length; i++) {
                                        //添加option元素
                                        $("#transReachSubstation").append("<option >" + data[i].substName + "</option>");
                                    }
                                    form.render();
                                }, error: function (data) {
                                    layer.msg('系统错误', {icon: 6, time: 1400});
                                }

                            });
                            //查询出发地
                            $.ajax({
                                type: 'post',

                                url: '/subtype',

                                dataType: 'json',

                                success: function (data) {
                                    //添加select第一个option
                                    $("#transStarting").append("<option selected value=''>请选择</option>");
                                    for (var i = 0; i < data.length; i++) {
                                        //添加option元素
                                        $("#transStarting").append("<option >"+ data[i].substName +"</option>");
                                    }
                                    form.render();
                                }, error: function (data) {
                                    layer.msg('系统错误', {icon: 6, time: 1400});
                                }

                            });
                            //执行一个laydate实例
                            laydate.render({
                                elem: '#transPromiseDate' //指定元素
                            });

                            $("#transNum").val(new Date().getTime());
                            $("#transDepartDate").val(data[0].carloadDate);
                            $("#transStarting").val(data[0].carloadStarting);
                            $("#transCarloadList").val(data[0].carloadlist);
                            $("#carloadTotalNum").val(data[0].carloadTotalNum);
                            $("#carloadTotalWeight").val(data[0].carloadTotalWeight);
                            $("#carloadTotalVolume").val(data[0].carloadTotalVolume);
                            $("#carloadOperator").val(data[0].carloadOperator);
                            $("#transCarloadSeqNum").val(data[0].carloadSeqNum);

                            //模糊查询司机
                            //定义个变量，判断司机有无
                            var pands = 0;
                            $("#Driver").on('input propertychange', function() {
                                pands = 0;
                                $("#divername ul li").each(function () {
                                    $(this).remove();
                                });
                                if($("#Driver").val()!=null&&$("#Driver").val()!=""){
                                    $.ajax({
                                        type: 'post',

                                        url: '/selectdriverinfo',

                                        dataType: 'json',
                                        data:{
                                            carDriver:$("#Driver").val(),
                                            startingSubst:$("#transStarting").val(),
                                        },
                                        success: function (data) {
                                            //添加select第一个option
                                            for (var i = 0; i < data.length; i++) {
                                                //添加option元素
                                                $("#divername ul").append("<li style=\" line-height: 35px;\" value='"+i+"' >" + data[i].carDriver + "</li>");
                                            }
                                            form.render();
                                            $("#divername ul li").click(function () {
                                                pands=1;
                                                var j =$(this).val();
                                                $("#Driver").val(data[j].carDriver);
                                                $("#transCarNumber").val(data[j].carNumber);
                                                $("#DriverMob").val(data[j].carDriverPhone);
                                                $("#VehicleSize").val(data[j].carType);
                                                $("#divername ul li").each(function () {
                                                    $(this).remove();
                                                });
                                            });
                                        }, error: function (data) {
                                            layer.msg('系统错误', {icon: 6, time: 1400});
                                        }

                                    });
                                }

                            });
                            //模糊查询收货人
                            $("#transReceivingCom").on('input propertychange', function() {
                                $("#consiCom ul li").remove();
                                /*$("#consiCom ul li").not(":eq(0)").remove();*/
                                $("#consiCom ul").append("<li style=\" line-height: 35px;\" value='1000' >添加收货人</li>");
                                if($("#transReceivingCom").val()!=null&&$("#transReceivingCom").val()!=""){
                                    $.ajax({
                                        type: 'post',

                                        url: '/selectconsinfo',

                                        dataType: 'json',
                                        data:{
                                            consiCom:$("#transReceivingCom").val()
                                        },
                                        success: function (data) {
                                            //添加select第一个option
                                            for (var i = 0; i < data.length; i++) {
                                                //添加option元素
                                                $("#consiCom ul").append("<li style=\" line-height: 35px;\" value='"+i+"' >" + data[i].consiCom + "</li>");
                                            }
                                            form.render();
                                            $("#consiCom ul li").click(function () {
                                                var j =$(this).val();
                                                if(j=="1000"){
                                                    window.sessionStorage.setItem("event","add");

                                                    var index = layer.open({
                                                        type:2,//设置类型 默认0 1页面层 2弹出层
                                                        title:'修改发货方资料',
                                                        skin:'layui-layer-molv',//皮肤
                                                        content: 'static/pages/ConsiLayer.html', //支持传入html
                                                        //大小
                                                        area:['1050px', '400px'],//'auto',
                                                        btnAlign :'c', //按钮对齐方式
                                                        closeBtn: 1, //关闭按钮样式默认1
                                                        shade:[0.8,'#393d49'],//遮罩：第一个参数透明度第二个参数颜色
                                                        shadeClose:true,//点击遮罩是否关闭弹出层默认是false
                                                        anim:1 //设置关闭动画
                                                    });
                                                }else {
                                                    $("#transReceivingCom").val(data[j].consiCom);
                                                    $("#transReveivingPers").val(data[j].consiPerson);
                                                    $("#transReveivingPhone").val(data[j].consiTelephone);
                                                    $("#transReveivingAddress").val(data[j].consiAddress);
                                                }
                                                $("#consiCom ul li").each(function () {
                                                    $(this).remove();
                                                });
                                            });
                                        }, error: function (data) {
                                            layer.msg('系统错误', {icon: 6, time: 1400});
                                        }

                                    });
                                }

                            });
                            //点击新增协议
                            form.on('submit(btnsave)', function(data){
                                if(parseInt($("#transFreightTotal").val())==parseInt($("#transCashpay").val())+parseInt($("#transBackPay").val())+parseInt($("#transSubstationPay").val())){
                                    var index = layer.load(1, {
                                        shade: [0.3, '#fff'], //0.1透明度的白色背景
                                    });
                                    //新增运输协议
                                    $.ajax({
                                        type: 'post',

                                        url: '/insertagreement',

                                        dataType: 'json',
                                        data: {
                                            transNum:$("#transNum").val()
                                            ,transCarloadSeqNum:$("#transCarloadSeqNum").val()
                                            ,transCarNumber:$("#transCarNumber").val()
                                            ,transDepartDate:$("#transDepartDate").val()
                                            , transStarting:$("#transStarting").val()
                                            , transReachCity:$("#transReachCity").val()
                                            , transReachSubstation:$("#transReachSubstation").val()
                                            , transReceivingCom:$("#transReceivingCom").val()
                                            , transReveivingPers:$("#transReveivingPers").val()
                                            , transReveivingPhone:$("#transReveivingPhone").val()
                                            , transReveivingAddress:$("#transReveivingAddress").val()
                                            ,transPromiseDate:$("#transPromiseDate").val()
                                            , transCarloadList:$("#transCarloadList").val()
                                            , transFreightTotal:$("#transFreightTotal").val()
                                            , transpayment:$("#transpayment").val()
                                            , transCashpay:$("#transCashpay").val()
                                            , transBackPay:$("#transBackPay").val()
                                            , transSubstationPay:$("#transSubstationPay").val()
                                            , transBillingperson:$("#carloadOperator").val()
                                        },
                                        success: function (data) {
                                            layer.close(index);
                                            layer.msg('新增成功', {icon: 6, time: 1400});
                                            if(pands==0){
                                                //添加司机
                                                $.ajax({
                                                    type: 'post',

                                                    url: '/insertdriver',

                                                    dataType: 'json',
                                                    data: {
                                                        carNumber:$("#transCarNumber").val()
                                                        ,carDriver:$("#Driver").val()
                                                        ,carDriverPhone:$("#DriverMob").val()
                                                        ,carType:$("#VehicleSize").val()
                                                        ,carPartofSubs:$("#transReachSubstation").val()
                                                    },
                                                    success: function (data) {

                                                    }, error: function (data) {
                                                        layer.msg('系统错误', {icon: 6, time: 1400});
                                                    }
                                                });
                                            }
                                            //修改装车表
                                            $.ajax({
                                                type: 'post',

                                                url: '/updatecar',

                                                dataType: 'json',
                                                data: {
                                                    carloadTransNum:$("#transNum").val()
                                                    ,carloadCarNum:$("#transCarNumber").val()
                                                    ,carloadSeqNum:$("#transCarloadSeqNum").val()
                                                },
                                                success: function (data) {

                                                    $(".page > .page-wrap").children().remove();
                                                    $(".page > .page-wrap").load("/addLoadingstowage .Conframe",function () {
                                                        form.render();
                                                        loading();
                                                    });
                                                }, error: function (data) {
                                                    layer.msg('系统错误', {icon: 6, time: 1400});
                                                }
                                            });
                                        }, error: function (data) {
                                            layer.msg('系统错误', {icon: 6, time: 1400});
                                        }
                                    });
                                }else {
                                    layer.msg('运费合计≠现付+回付+分站支付', {
                                        time: 1000, //20s后自动关闭
                                    });
                                }
                                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                            });
                        });
                    }

                }
            });
        }
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/addLoadingstowage .Conframe",function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            form.render();
            loading();

        });
    });

    /*发车列表*/
    $(".list-trans >.layui-nav-child > dd > a.nav-trans-list").click(function () {
        function loadings(){
            //第一个实例
            table.render({
                elem: '#demo'
                ,id:'demo'
                ,width: 3400
                ,height: 380
                ,url:'depatlist'//数据接口
                ,page: true //开启分页
                ,limit:5
                ,limits:[1, 2, 3,4,5]
                ,cols: [[ //表头
                    {type: 'checkbox',fixed: 'left' }
                    ,{field: 'transCarloadSeqNum', title: '装车序号', width:110, sort: true}
                    ,{field: 'transNum', title: '运输单号', width:150}
                    ,{field: 'carloadlist',title: '装车清单', width: 170}
                    /* ,{field: 'transCarloadSeqNum',title: '运单收入', width: 110, sort: true}*/
                    ,{field: 'transDepartDate',title: '发车日期', width: 180, sort: true}
                    ,{field: 'transStarting', title: '出发站', width: 110, sort: true}
                    ,{field: 'transReachCity', title: '到达城市', width: 120, sort: true}
                    ,{field: 'transFreightTotal', title: '运输合计', width: 110, sort: true}
                    ,{field: 'transCashpay', title: '现付', width: 80, sort: true}
                    ,{field: 'transSubstationPay', title: '分站到付', width: 135, sort: true}
                    ,{field: 'transBackPay', title: '运输回付', width: 135, sort: true}
                    ,{field: 'transCarNumber', title: '车号', width: 135, sort: true}
                    ,{field: 'carDriver', title: '司机', width: 135, sort: true}
                    ,{field: 'carDriverPhone', title: '手机', width: 135, sort: true}
                    ,{field: 'transReceivingCom', title: '收货单位', width: 135, sort: true}
                    ,{field: 'transReveivingPers', title: '收货人', width: 135, sort: true}
                    ,{field: 'transReveivingPhone', title: '电话', width: 130, sort: true}
                    /* ,{field: 'transCarloadSeqNum', title: '手机', width: 110, sort: true}*/
                    ,{field: 'transReveivingAddress',title: '地址', width: 160, sort: true}
                    ,{field: 'waybillCargoName',title: '货名', width: 110}
                    ,{field: 'carloadWaybillNum', title: '数量', width: 110, sort: true}
                    ,{field: 'waybillPackingWay', title: '包装', width: 110, sort: true}
                    ,{field: 'carloadTotalWeight', title: '重量/KG', width: 135, sort: true}
                    ,{field: 'carloadTotalVolume', title: '总体积/m³', width: 135, sort: true}
                    ,{field: 'waybillRemark', title: '备注', width: 135, sort: true}
                    ,{field: 'transDepartDate', title: '开单时间', width: 180, sort: true}
                    ,{field: 'transBillingperson', title: '开单人', width: 135, sort: true}
                ]]


            });
            //执行一个laydate实例
            laydate.render({
                elem: '#startdate' //指定元素
                , range: true //或 range: '~' 来自定义分割字符
            });

            //查询分站
            $.ajax({
                type: 'post',

                url: '/subtype',

                dataType: 'json',

                success: function (data) {
                    //添加select第一个option
                    $("#ComeStation").append("<option selected value=''>请选择</option>");
                    for (var i = 0; i < data.length; i++) {
                        //添加option元素
                        $("#ComeStation").append("<option >" + data[i].substName + "</option>");
                    }
                    form.render();
                }, error: function (data) {
                    layer.msg('系统错误', {icon: 6, time: 1400});
                }

            });
            //查询出发地
            $.ajax({
                type: 'post',

                url: '/subtype',

                dataType: 'json',

                success: function (data) {
                    //添加select第一个option
                    $("#StartStation").append("<option selected value=''>请选择</option>");
                    for (var i = 0; i < data.length; i++) {
                        //添加option元素
                        $("#StartStation").append("<option >"+ data[i].substName +"</option>");
                    }
                    form.render();
                }, error: function (data) {
                    layer.msg('系统错误', {icon: 6, time: 1400});
                }

            });
            //筛选查询
            $("#select").click(function () {
                //substr 方法用于返回一个从指定位置开始的指定长度的子字符串
                var Date1 =  $("#startdate").val().substr(0,10);
                var Date2 = $("#startdate").val().substr(12,22);
                //执行重载
                table.reload('demo', {
                    method:"post"
                    ,url:"depatlist"
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        transDepartDate: Date1,
                        transPromiseDate: Date2,
                        transReachSubstation :  $("#ComeStation").val(),
                        transReachCity: $("#City").val(),
                        transStarting: $("#StartStation").val(),
                        transNum:$("#TransNum").val(),
                        carloadlist:$("#Carloadlist").val(),
                        carDriver:$("#CarDriver").val(),
                        transCarNumber:$("#CarNumber").val()
                    }
                });
            });
            //删除协议
            $("#delete").click(function () {
                var checkStatus = table.checkStatus('demo');
                var data = checkStatus.data;
                if (data.length==0){
                    layer.msg('请至少选中一行', {
                        time: 1000, //20s后自动关闭
                    });
                }else if (data.length>=1){
                    var ids = [];
                    var id = [];
                    var carloadlist = [];
                    //因为是json格式所以循环
                    for(var i = 0;i < data.length;i++){

                        // 将选中的行保存到数组
                        ids.push(data[i].transNum);
                        id.push(data[i].transCarloadSeqNum);
                        carloadlist.push(data[i].carloadlist);
                    }
                    var index = layer.load(1, {
                        shade: [0.3, '#fff'], //0.1透明度的白色背景
                    });
                    $.ajax({
                        url:'deletecarlist',
                        type:'post',
                        dataType:'json',
                        data:{
                            ids:ids.join(','),
                            id:id.join(','),
                            carloadlist:carloadlist.join(',')
                        },
                        success:function(data){
                            layer.close(index);
                            if (data==3){
                                table.reload('demo',{});
                            }else {
                                layer.msg('已经在运输途中，不能删除协议', {
                                    time: 1000, //20s后自动关闭
                                });
                            }
                        }
                    });
                }
            })

            //修改协议
            $("#update").click(function () {
                var checkStatus = table.checkStatus('demo');
                var data = checkStatus.data;
                if (data.length==0){
                    layer.msg('请至少选中一行', {
                        time: 1000, //20s后自动关闭
                    });
                }else if(data.length==1){
                    $(".page > .page-wrap").children().remove();
                    $(".page > .page-wrap").load("/addtraprotocol .common-body", function () {
                        form.render();
                        //运费合计
                        $(".num").change(function () {
                            var pand =true;
                            var sum = 0;
                            if ($("#transCashpay").val()!=""&&$("#transBackPay").val()!=""&&$("#transSubstationPay").val()!=""){
                                for(var i=0;i<$(".num").length;i++){
                                    var b = String($(".num:eq("+i+")").val()).split('');
                                    sum=sum+parseInt($(".num:eq("+i+")").val());
                                    for (var j=0;j<b.length;j++){
                                        if(!isNaN(b[j])){
                                        }else {
                                            pand=false;
                                        }
                                    }
                                }
                                if(pand){
                                    $("#transFreightTotal").val(sum);
                                }else {
                                    layer.msg('请输入正确的金额格式', {icon: 6, time: 1400});
                                }
                            }

                        })
                        //模糊查询司机
                        //定义个变量，判断司机有无
                        var pands = 0;
                        $("#Driver").on('input propertychange', function() {
                            pands = 0;
                            $("#divername ul li").each(function () {
                                $(this).remove();
                            });
                            if($("#Driver").val()!=null&&$("#Driver").val()!=""){
                                $.ajax({
                                    type: 'post',

                                    url: '/selectdriverinfo',

                                    dataType: 'json',
                                    data:{
                                        carDriver:$("#Driver").val(),
                                        startingSubst:$("#transStarting").val(),
                                    },
                                    success: function (data) {
                                        //添加select第一个option
                                        for (var i = 0; i < data.length; i++) {
                                            //添加option元素
                                            $("#divername ul").append("<li value='"+i+"' >" + data[i].carDriver + "</li>");
                                        }
                                        form.render();
                                        $("#divername ul li").click(function () {
                                            pands=1;
                                            var j =$(this).val();
                                            $("#Driver").val(data[j].carDriver);
                                            $("#transCarNumber").val(data[j].carNumber);
                                            $("#DriverMob").val(data[j].carDriverPhone);
                                            $("#VehicleSize").val(data[j].carType);
                                            $("#divername ul li").each(function () {
                                                $(this).remove();
                                            });
                                        });
                                    }, error: function (data) {
                                        layer.msg('系统错误', {icon: 6, time: 1400});
                                    }

                                });
                            }

                        });
                        //模糊查询收货人
                        $("#transReceivingCom").on('input propertychange', function() {
                            $("#consiCom ul li").each(function () {
                                $(this).remove();
                            });
                            if($("#transReceivingCom").val()!=null&&$("#transReceivingCom").val()!=""){
                                $.ajax({
                                    type: 'post',

                                    url: '/selectconsinfo',

                                    dataType: 'json',
                                    data:{
                                        consiCom:$("#transReceivingCom").val()
                                    },
                                    success: function (data) {
                                        //添加select第一个option
                                        for (var i = 0; i < data.length; i++) {
                                            //添加option元素
                                            $("#consiCom ul").append("<li value='"+i+"' >" + data[i].consiCom + "</li>");
                                        }
                                        form.render();
                                        $("#consiCom ul li").click(function () {
                                            var j =$(this).val();
                                            $("#transReceivingCom").val(data[j].consiCom);
                                            $("#transReveivingPers").val(data[j].consiPerson);
                                            $("#transReveivingPhone").val(data[j].consiTelephone);
                                            $("#transReveivingAddress").val(data[j].consiAddress);
                                            $("#consiCom ul li").each(function () {
                                                $(this).remove();
                                            });
                                        });
                                    }, error: function (data) {
                                        layer.msg('系统错误', {icon: 6, time: 1400});
                                    }

                                });
                            }

                        });
                        //查询分站
                        $.ajax({
                            type: 'post',

                            url: '/subtype',

                            dataType: 'json',

                            success: function (data) {
                                //添加select第一个option
                                $("#transReachSubstation").append("<option selected value=''>请选择</option>");
                                for (var i = 0; i < data.length; i++) {
                                    //添加option元素
                                    $("#transReachSubstation").append("<option value='" + data[i].substName + "'>" + data[i].substName + "</option>");
                                }
                                form.render();
                            }, error: function (data) {
                                layer.msg('系统错误', {icon: 6, time: 1400});
                            }

                        });
                        //查询出发地
                        $.ajax({
                            type: 'post',

                            url: '/subtype',

                            dataType: 'json',

                            success: function (data) {
                                //添加select第一个option
                                $("#transStarting").append("<option selected value=''>请选择</option>");
                                for (var i = 0; i < data.length; i++) {
                                    //添加option元素
                                    $("#transStarting").append("<option value='" + data[i].substName + "'>"+ data[i].substName +"</option>");
                                }
                                form.render();
                            }, error: function (data) {
                                layer.msg('系统错误', {icon: 6, time: 1400});
                            }

                        });
                        //执行一个laydate实例
                        laydate.render({
                            elem: '#transPromiseDate' //指定元素
                        });

                        //查询发车列表数据
                        $.ajax({
                            type: 'post',

                            url: '/selectcarlist',

                            dataType: 'json',
                            data: {
                                id:data[0].transNum,
                            },
                            success: function (data) {
                                $("#transNum").val(data[0].transNum);
                                $("#transDepartDate").val(data[0].transDepartDate);
                                $("#transStarting").val(data[0].transStarting);
                                $("#transReachCity").val(data[0].transReachCity);
                                $("#transReachSubstation").val(data[0].transReachSubstation);
                                $("#Driver").val(data[0].carDriver);
                                $("#transCarNumber").val(data[0].transCarNumber);
                                $("#VehicleType").val(data[0].carloadSeqNum);
                                $("#DriverMob").val(data[0].carDriverPhone);
                                $("#VehicleSize").val(data[0].carType);
                                $("#transReceivingCom").val(data[0].transReceivingCom);
                                $("#transReveivingPers").val(data[0].transReveivingPers);
                                $("#transReveivingPhone").val(data[0].transReveivingPhone);
                                $("#transReveivingAddress").val(data[0].transReveivingAddress);
                                $("#transPromiseDate").val(data[0].transPromiseDate);
                                $("#transCarloadList").val(data[0].transCarloadList);
                                $("#carloadTotalNum").val(data[0].carloadTotalNum);
                                $("#carloadTotalWeight").val(data[0].carloadTotalWeight);
                                $("#carloadTotalVolume").val(data[0].carloadTotalVolume);

                                $("#transFreightTotal").val(data[0].transFreightTotal);
                                $("#transCashpay").val(data[0].transCashpay);
                                $("#transpayment").val(data[0].transpayment);
                                $("#transBackPay").val(data[0].transBackPay);
                                $("#transSubstationPay").val(data[0].transSubstationPay);
                                $("#carloadOperator").val(data[0].transBillingperson);
                                $("#transCarloadSeqNum").val(data[0].transCarloadSeqNum);
                                $("#btnsave").val("修改协议");
                                form.render();
                            }, error: function (data) {
                                layer.msg('系统错误', {icon: 6, time: 1400});
                            }

                        });
                        //修改运输协议
                        form.on('submit(btnsave)', function(data) {
                            if (parseInt($("#transFreightTotal").val()) == parseInt($("#transCashpay").val()) + parseInt($("#transBackPay").val()) + parseInt($("#transSubstationPay").val())) {
                                var index = layer.load(1, {
                                    shade: [0.3, '#ffffff'], //0.1透明度的白色背景
                                });
                                $.ajax({
                                    type: 'post',
                                    url: '/updatecarlist',
                                    dataType: 'json',
                                    data: {
                                        transNum:$("#transNum").val()
                                        ,transCarloadSeqNum:$("#transCarloadSeqNum").val()
                                        ,transCarNumber:$("#transCarNumber").val()
                                        ,transDepartDate:$("#transDepartDate").val()
                                        , transStarting:$("#transStarting").val()
                                        , transReachCity:$("#transReachCity").val()
                                        , transReachSubstation:$("#transReachSubstation").val()
                                        , transReceivingCom:$("#transReceivingCom").val()
                                        , transReveivingPers:$("#transReveivingPers").val()
                                        , transReveivingPhone:$("#transReveivingPhone").val()
                                        , transReveivingAddress:$("#transReveivingAddress").val()
                                        ,transPromiseDate:$("#transPromiseDate").val()
                                        , transCarloadList:$("#transCarloadList").val()
                                        , transFreightTotal:$("#transFreightTotal").val()
                                        , transpayment:$("#transpayment").val()
                                        , transCashpay:$("#transCashpay").val()
                                        , transBackPay:$("#transBackPay").val()
                                        , transSubstationPay:$("#transSubstationPay").val()
                                        , transBillingperson:$("#carloadOperator").val()
                                    },
                                    success: function (data) {
                                        layer.close(index);
                                        layer.msg('修改成功', {icon: 6, time: 1400});
                                        //修改装车表
                                        $.ajax({
                                            type: 'post',

                                            url: '/updatecar',

                                            dataType: 'json',
                                            data: {
                                                carloadTransNum:$("#transNum").val()
                                                ,carloadCarNum:$("#transCarNumber").val()
                                                ,carloadSeqNum:$("#transCarloadSeqNum").val()
                                            },
                                            success: function (data) {
                                                $(".page > .page-wrap").children().remove();
                                                $(".page > .page-wrap").load("/depart .Departlist",function () {
                                                    form.render();
                                                    loadings();

                                                });
                                            }, error: function (data) {
                                                layer.msg('系统错误', {icon: 6, time: 1400});
                                            }
                                        });
                                    }, error: function (data) {
                                        layer.msg('系统错误', {icon: 6, time: 1400});
                                    }
                                });
                            }
                            return false ;
                        });

                    });
                }
            });
        }
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/depart .Departlist",function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            form.render();
            loadings();
        });
    });




    /*车辆管理w*/
    /*车辆列表*/
    $(".list-car > .layui-nav-child > dd > a.nav-car-list").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goVehicleList .page-this",function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            /*刷新分站下拉框*/
            refresh();
            /*分页查询车辆信息表*/
            table.render({
                id:'vehicleTable'//表格id
                ,elem:'#vehicleTable'//渲染对象
                ,url:'/selectCarInfoPaing'//数据接口
                ,cellMinWidth:80//全局单元格最小宽度
                ,page:true//开启分页
                ,limit:6//默认显示6页
                ,limits:[2,4,6,8,10]
                ,cols:[[
                    {field:'carNumber',title:'车号',width:100}
                    ,{field:'carDriver',title:'司机'}
                    ,{field:'carDriverPhone',title:'手机号码',width:130}
                    ,{title:'所属分站',templet:'<div>{{d.subst.substName}}</div>'}
                    ,{field:'carType',title:'车辆类型'}
                    ,{field:'carLength',title:'车辆长度'}
                    ,{field:'carMaxLoad',title:'车辆载重'}
                    ,{field:'carAccount',title:'司机账号',width:130}
                    ,{field:'right',title:'操作',toolbar:'#barDemo',width:120}
                ]]
            });
            /*动态模糊查询*/
            form.on('submit(query)',function (data) {
                console.log(data.field);
                table.reload('vehicleTable', {//参数为表格id值
                    url: '/dynamicSqlQuery'
                    ,method:'post'
                    ,where: data.field
                });
                return false;
            });
            /*新增车辆信息*/
            $('.loadVehicle').click(function () {
                $(".page > .page-wrap").children().remove();
                $(".page > .page-wrap").load("/loadVehicle .page-this",function () {
                    /*刷新分站下拉框*/
                    refresh();
                    /*新增车辆*/
                    form.on('submit(addVehicle)',function (data) {
                        console.log(data.field);
                        $.ajax({
                            type:'post'
                            ,url:'/addVehicle'
                            ,data:data.field
                            ,success:function (data) {
                                layer.msg(data['msg'], {icon: 6, time: 1400});
                            }
                        })
                        return false;
                    })
                });
            });
            /*监听行工具事件*/
            table.on('tool(vehicleTable)', function(obj){//参数为表格lay-filter值
                var data = obj.data;//获取当前行数据
                var carNumber = data.carNumber;//获取主键id
                if(obj.event === 'del'){//判断是否删除按钮
                    layer.confirm('真的删除行么', function(index){
                        $.ajax({
                            type:"post",
                            url:"/deleteVehicleDate",
                            data:{carNumber:carNumber},
                            dataType:"text",
                            success:function (data) {
                                layer.close(index);//关闭弹出层
                                layer.msg(data['msg'], {icon: 6, time: 1400});
                                //新增成功后刷新父界面
                                table.reload('vehicleTable');//参数为数据表格id
                            }
                        });
                    });
                }else if (obj.event === 'edit'){
                    /*加载修改页面*/
                    $(".page > .page-wrap").children().remove();
                    $(".page > .page-wrap").load("/goUpdateVehicle .page-this",function () {
                        /*下拉框刷新*/
                        refresh();
                        /*根据id查询数据*/
                        $.ajax({
                            type:"post"
                            ,url:"/byIdQueryVehicle"
                            ,data:{carNumber:carNumber}
                            ,success:function (data) {
                                console.log(data);
                                form.val("updateVehicle",{//参数是表单的lay-filter值
                                    carDriver: data['carDriver'],//司机姓名
                                    carNumber: data['carNumber'],//车牌号码
                                    carDriverPhone: data['carDriverPhone'],//司机电话
                                    carMaxLoad: data['carMaxLoad'],//最大载重
                                    carType: data['carType'],//车辆类型
                                    carLength: data['carLength'],//车辆长度
                                    carAccount: data['carAccount'],//司机账号
                                    carPartofSubs: data['carPartofSubs']//司机所属分站
                                });
                                //表单的监听提交
                                form.on('submit(updateVehicle)', function(data){//参数为按钮lay-filter值
                                    console.log(data.field);
                                    $.ajax({
                                        type: "post",
                                        url: "/updateVehicle",
                                        data: data.field,
                                        success: function (data) {
                                            console.log(data);
                                            layer.msg(data['msg'], {icon: 6, time: 1400});
                                        }
                                    });
                                    return false;
                                });
                            }
                        })

                    });
                }
            });
            //下拉框刷新
            function refresh() {
                $.ajax({
                    type: "POST",
                    url: "/getSubstationListFS",
                    success: function(data){
                        for (var i = 0; i < data.length; i++) {
                            var li = "<option value='"+data[i]['substId']+"'>"+data[i]['substName']+"</option>"
                            $("select[name='carPartofSubs']").append(li);
                        }
                        form.render("select");
                    }
                });
            }
            form.render();//只有执行了这一步，部分表单元素才会自动修饰成功
        });
    });

    //车辆定位
    $(".list-car > .layui-nav-child > dd > a.nav-car-GPS").click(function () {
        window.open("/carGPS","block");
    });


    /*客户模块w*/
    /*发货方w*/
    $(".list-cust > .layui-nav-child > dd >a.nav-shipper").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goShipper .pege-this",function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            /*分页查询发货方数据*/
            table.render({
                id:'shipperTable'//数据表格id
                ,elem:'#shipperTable'//表格id，渲染对象
                ,url:'/selectShipperPaing'//数据接口
                ,cellMinWidth: 120 //单元格最小宽度
                ,page:true//开启分页
                ,limit:4//显示页目
                ,limits:[2,4,6,8]//页目数
                ,cols:[[
                    {field:'shipperId',title:'发货方id',sort: true}
                    ,{field:'shipperCom',width:150,title:'发货单位'}
                    ,{field:'shipperPerson',title:'发货人'}
                    ,{field:'shipperTelephone',width:150,title:'发货人电话'}
                    ,{field:'shipperAddress',title:'发货地址'}
                    ,{field:'shipperDetailAddress',title:'发货详细地址'}
                    ,{title:'发货人用户等级',templet:function (d) {
                            var str;
                            if(d.shipperGrade == 1){
                                str = '优质';
                            }else if (d.shipperGrade == 2){
                                str = '良好';
                            }else if (d.shipperGrade == 3){
                                str = '一般';
                            }else if (d.shipperGrade == 4){
                                str = '糟糕';
                            }
                            return str;
                        }}
                    ,{field:'shipperBankcard',title:'发货人银行卡'}
                    ,{field:'shipperBankcardNum',title:'发货人银行卡号'}
                    ,{field:'shipperWeixin',title:'发货人微信账号'}
                    ,{field:'shipperRemark',title:'发货人备注'}
                    ,{width:150,title:'发货人提交人',templet:'<div>{{d.empInfo.empName}}</div>'}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo',}
                ]]

            });
            /*发货单位模糊查询*/
            $('.shipperSearch').click(function () {
                var shipperCom = $('.shipperCom').val();//获取发货单位
                table.reload('shipperTable',{//参数为表格id值
                    url:'/likeSelectShipperCom'
                    ,method:'post'
                    ,where:{
                        shipperCom:shipperCom
                    }
                })
            });
            /*新增发货方*/
            $('.loadShipper').click(function () {
                window.sessionStorage.setItem("event","add");

                var index = layer.open({
                    type:2,//设置类型 默认0 1页面层 2弹出层
                    title:'新增发货方资料',
                    skin:'layui-layer-molv',//皮肤
                    content: 'static/pages/shipperLayer.html', //支持传入html
                    //大小
                    area:['1050px', '400px'],//'auto',
                    btnAlign :'c', //按钮对齐方式
                    closeBtn: 1, //关闭按钮样式默认1
                    shade:[0.8,'#393d49'],//遮罩：第一个参数透明度第二个参数颜色
                    shadeClose:true,//点击遮罩是否关闭弹出层默认是false
                    anim:1 //设置关闭动画
                });
            });
            /*监听行内工具*/
            table.on('tool(shipperTable)',function (obj) {//参数表格id值
                var data = obj.data;//获取当前行数据
                if(obj.event === 'del'){//判断是否删除按钮
                    layer.open({
                        type: 0,
                        title: "温馨提示",
                        content: "您确定要删除吗？",
                        btn: ['确定','取消'],
                        yes:function(){
                            //根据托运单号删除对应运单信息
                            $.ajax({
                                url: "/deleteShipper",
                                type: "POST",
                                data:{shipperId:data.shipperId},
                                success: function (data) {
                                    layer.msg(data['msg'], {icon: 6, time: 1400});
                                    table.reload('shipperTable');
                                }
                            });
                        }
                    });
                }else if(obj.event === 'edit'){//判断是否修改按钮
                    window.sessionStorage.setItem("event",obj.event);
                    window.sessionStorage.setItem("shipperId",data.shipperId);

                    var index = layer.open({
                        type:2,//设置类型 默认0 1页面层 2弹出层
                        title:'修改发货方资料',
                        skin:'layui-layer-molv',//皮肤
                        content: 'static/pages/shipperLayer.html', //支持传入html
                        //大小
                        area:['1050px', '400px'],//'auto',
                        btnAlign :'c', //按钮对齐方式
                        closeBtn: 1, //关闭按钮样式默认1
                        shade:[0.8,'#393d49'],//遮罩：第一个参数透明度第二个参数颜色
                        shadeClose:true,//点击遮罩是否关闭弹出层默认是false
                        anim:1 //设置关闭动画
                    });
                }
            })
        });
    });
    /*收货方w*/
    $(".list-cust > .layui-nav-child > dd >a.nav-consi").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goConsignee .pege-this",function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            /*分页查询收货方数据*/
            table.render({
                id:'consiTable'//数据表格id
                ,elem:'#consiTable'//表格id，渲染对象
                ,url:'/selectConsiPaing'//数据接口
                ,cellMinWidth: 120 //单元格最小宽度
                ,page:true//开启分页
                ,limit:4//显示页目
                ,limits:[2,4,6,8]//页目数
                ,cols:[[
                    {field:'consiId',title:'收货方id',sort: true}
                    ,{field:'consiCom',width:150,title:'收货单位'}
                    ,{field:'consiPerson',title:'收货人'}
                    ,{field:'consiTelephone',width:150,title:'收货人电话'}
                    ,{field:'consiAddress',title:'收货地址'}
                    ,{field:'consiDetailAddress',title:'收货详细地址'}
                    ,{title:'收货人用户等级',templet:function (d) {
                            var str;
                            if(d.consiGrade == 1){
                                str = '优质';
                            }else if (d.consiGrade == 2){
                                str = '良好';
                            }else if (d.consiGrade == 3){
                                str = '一般';
                            }else if (d.consiGrade == 4){
                                str = '糟糕';
                            }
                            return str;
                        }}
                    ,{field:'consiBankcard',title:'收货人银行卡'}
                    ,{field:'consiBankcardNum',title:'收货人银行卡号'}
                    ,{field:'consiWeixin',title:'收货人微信账号'}
                    ,{field:'consiRemark',title:'收货人备注'}
                    ,{width:150,title:'收货人提交人',templet:'<div>{{d.empInfo.empName}}</div>'}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo',}
                ]]

            });
            /*收货单位模糊查询*/
            $('.consiSearch').click(function () {
                var consiCom = $('.consiCom').val();//获取收货单位
                table.reload('consiTable',{//参数为表格id值
                    url:'/likeSelectConsiCom'
                    ,method:'post'
                    ,where:{
                        consiCom:consiCom
                    }
                })
            });
            /*新增收货方*/
            $('.loadConsi').click(function () {
                window.sessionStorage.setItem("event","add");

                var index = layer.open({
                    type:2,//设置类型 默认0 1页面层 2弹出层
                    title:'添加收货方资料',
                    skin:'layui-layer-molv',//皮肤
                    content: 'static/pages/consiLayer.html', //支持传入html
                    //大小
                    area:['1050px', '400px'],//'auto',
                    btnAlign :'c', //按钮对齐方式
                    closeBtn: 1, //关闭按钮样式默认1
                    shade:[0.8,'#393d49'],//遮罩：第一个参数透明度第二个参数颜色
                    shadeClose:true,//点击遮罩是否关闭弹出层默认是false
                    anim:1 //设置关闭动画
                });
            });
            /*监听行内工具*/
            table.on('tool(consiTable)',function (obj) {//参数表格id值
                var data = obj.data;//获取当前行数据
                if(obj.event === 'del'){//判断是否删除按钮
                    layer.open({
                        type: 0,
                        title: "温馨提示",
                        content: "您确定要删除吗？",
                        btn: ['确定','取消'],
                        yes:function(){
                            //根据托运单号删除对应运单信息
                            $.ajax({
                                url: "/deleteConsi",
                                type: "POST",
                                data:{consiId:data.consiId},
                                success: function (data) {
                                    layer.msg(data['msg'], {icon: 6, time: 1400});
                                    table.reload('consiTable');//参数为数据表格id
                                }
                            });
                        }
                    });
                }else if(obj.event === 'edit'){//判断是否修改按钮
                    window.sessionStorage.setItem("event",obj.event);
                    window.sessionStorage.setItem("consiId",data.consiId);

                    var index = layer.open({
                        type:2,//设置类型 默认0 1页面层 2弹出层
                        title:'修改收货方资料',
                        skin:'layui-layer-molv',//皮肤
                        content: 'static/pages/consiLayer.html', //支持传入html
                        //大小
                        area:['1050px', '400px'],//'auto',
                        btnAlign :'c', //按钮对齐方式
                        closeBtn: 1, //关闭按钮样式默认1
                        shade:[0.8,'#393d49'],//遮罩：第一个参数透明度第二个参数颜色
                        shadeClose:true,//点击遮罩是否关闭弹出层默认是false
                        anim:1 //设置关闭动画
                    });
                }
            })
        });
    });
    /*新增签收w*/
    $(".list-track > .layui-nav-child > dd > a.nav-sign-for").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAddSignfor .page-this", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            /*加载时间选择框*/
            laydate.render({
                elem: '#time'
                ,type: 'datetime'
            });
            /*查询已签收运单信息*/
            table.render({
                id:'signforTable'//表格id
                ,elem:'#signforTable'//渲染对象
                ,url:'/selectSignforPaing'//数据接口
                ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                ,page: true//开启分页
                ,limit:4//默认显示6页
                ,limits:[2, 4, 6, 8, 10]
                ,cols: [
                    [//列表数据
                        {field:'trackConsignNum', title: '托运单号'}
                        ,{field:'trackDate', title: '跟踪日期'} //width 支持：数字、百分比和不填写。你还可以通过 minWidth 参数局部定义当前单元格的最小宽度，layui 2.2.1 新增
                        ,{title: '跟踪类型',templet:function (d) {
                            var str;
                            if(d.trackType == 7){
                                str = '签收';
                            }
                            return str;
                        }}
                        ,{field:'trackStatus', title: '跟踪状态'}
                        ,{field:'trackReceiptPhotoUrl',title: '回单照片'} //单元格内容水平居中
                    ]
                ]
            });
            /*根据托运单号查询数据*/
            $('.selectSignfor').click(function () {
                var trackConsignNum = $(".trackConsignNum").val();
                table.reload('signforTable', {//参数为表格id值
                    url: '/bytrackConsignNumSelect'
                    ,method:'post'
                    ,where: {
                        trackConsignNum:trackConsignNum
                    }
                });
            });
            /*加载派送中的托运单号*/
            $.ajax({
                type: "POST",
                url: "/getTrackConsignNum",
                success: function(data){
                    for (var i = 0; i < data.length; i++) {
                        var li = "<option value='"+data[i]['trackId']+"'>"+data[i]['trackConsignNum']+"</option>"
                        $("select[name='trackConsignNum']").append(li);
                    }
                    form.render("select");
                }
            });
            /*加载当前分站司机*/
            form.on('select(trackConsignNum)', function(data){
                $("select[name='signDriver']").find("option").remove();
                var trackConsignNum = data.value;
                /*根据运单运单单号查询到达站*/
                $.ajax({
                    type:'post'
                    ,url:'/byTrackConsignNumQueryDriver'
                    ,data:{trackConsignNum:trackConsignNum}
                    ,success:function (data) {
                        for (var i = 0; i < data.length; i++) {
                            var li = "<option>"+data[i]['carInfo']['carDriver']+"</option>"
                            $("select[name='signDriver']").append(li);
                        }
                        form.render("select");
                    }
                })
            });
            //选完文件后不自动上传
            upload.render({
                elem: '#file'//选择文件按钮
                ,url: '/uploadFile' //改成您自己的上传接口
                ,auto: false//是否选完文件后自动上传。
                ,multiple: false//是否允许多文件上传。
                ,bindAction: '#upload'//开始上传按钮id
                ,done: function(res){
                    //上传完毕回调
                    layer.alert("上传成功！", {
                        icon: 5,
                        title: "提示"
                    });
                    $("#trackReceiptPhotoUrl").val(res.msg);

                }
                ,error: function(res){
                    //请求异常回调
                    layer.alert("后台出错", {
                        icon: 5,
                        title: "提示"
                    });
                }
            });
            /*新增签收*/
            form.on('submit(addSignfor)',function (data) {
                var data = data.field;
                $.ajax({
                    type:'post'
                    ,url:'/addSignfor'
                    ,data:{
                        trackConsignNum : data.trackConsignNum,
                        trackDate : data.trackDate,
                        trackStatus : data.trackStatus,
                        signDriver : data.signDriver,
                        trackReceiptPhotoUrl : data.trackReceiptPhotoUrl
                    }
                    ,success:function (data) {
                        layer.msg(data['msg'], {icon: 6, time: 1400});
                        //刷新表格
                        table.reload('signforTable');//参数为表格id
                    }
                })
                return false;
            });
            form.render();
        });
    });

    /*员工管理*/
    $(".list-sys > .layui-nav-child > dd > a.nav-emp-list").click(function () {

        function empAll(){
            layui.use('table', function () {

                var table = layui.table;
                table.render({
                    id: 'te'
                    ,elem: '#emp-table'
                    , url: '/empAdmin'
                    , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                    , cols: [[
                        {type:'checkbox',fixed:'empAccount',name:'test'}
                        , {type: 'numbers', width: 57, title: '#'}
                        , {field: 'empAccount', width: 226, title: '员工账号',align:'center'}
                        , {field: 'empName', width: 226, title: '员工姓名',align:'center'}
                        , {templet: '<div>{{d.subst.substName}}</div>', title: '所在站点', width: 226,align:'center'}
                        , {field: 'empTelephone', title: '员工手机', width: 226,align:'center'}
                        , {field: 'empAccountStatus', width: 226, title: '账户状态',align:'center'}
                    ]],
                    done: function(){
                        $("[data-field='empAccountStatus']").children().each(function(){
                            if($(this).text()=='1'){
                                $(this).text("正常")
                            }else if($(this).text()=='2'){
                                $(this).text("锁定")
                            }
                        });
                    }
                });
            });
            //新增员工
            $("#addEmp").click(function () {
                $(".page > .page-wrap").children().remove();
                $(".page > .page-wrap").load("/addEmp .page-addEmp", function () {

                    /*新增员工页面*/
                    $.ajax({
                        type:"post"
                        ,url:"pageModel"
                        ,dataType:"json"
                        ,success:function (data) {

                            var modelAuthArr = {length:0};
                            for (var i = 0; i < data.length; i++) {
                                modelAuthArr['empModel'+data[i]['empModel']['mauthId']] = data[i]['empModel'];
                                modelAuthArr['length'] += 1;
                            }

                            var authChecks = '';
                            var button = "";

                            var isFirst = true;
                            $.each(modelAuthArr,function (attrname,item) {

                                if (attrname != 'length'){

                                    var tr = '<tr>';

                                    //判断是否有标题td列
                                    if (isFirst == true){
                                        tr += '<td rowspan="'+modelAuthArr.length+'" class="class-title">页面权限:' +
                                            '<input type="button" value="权限全选" id="check1">' +
                                            '</td>';
                                        isFirst = false;
                                    }
                                    /*模块td列*/
                                    tr += '<td class="td-admin">'
                                        +'<input type="checkbox" lay-filter="mauthId" lay-skin="primary" name="mauthId" title="'+item['mauthName']+'" value="'+item['mauthId']+'"/>'
                                        +'</td>';
                                    //单个页面访问权限
                                    tr += '<td colspan="'+8+'" class="td-left"><div class="div-checkbox">'
                                    for (var i = 0; i < data.length; i++) {
                                        if (data[i]['pauthMauthId'] == item['mauthId']){
                                            tr += '<input type="checkbox" lay-filter="pauthId" lay-skin="primary" title="'+data[i]['pauthName']+'" value="'+data[i]['pauthId']+'" name="pauthId"/>';
                                        }
                                    }

                                    tr += '</div></td>';
                                    tr += '</tr>';

                                    authChecks += tr;
                                }
                            });


                            button += '<td colspan="'+9+'"><div class="td-left-button">'
                                +'<button id="save-Employee" class="layui-btn" lay-submit lay-filter="insetEmp">新增员工</button>'+'</div>'
                                +'</td>';

                            $("table#emp-page").append(authChecks,button);

                            //加载分站下拉框
                            loadSubstList("empSubstId");

                            //监听模块权限checkbox
                            form.on('checkbox(mauthId)', function(data){
                                if (data.elem.checked == true){
                                    $(data.othis).parent().next().find("div.div-checkbox > input[name='pauthId']").prop("checked",true);
                                }else {
                                    $(data.othis).parent().next().find("div.div-checkbox > input[name='pauthId']").prop("checked",false);
                                }
                                form.render("checkbox");
                            });

                            //监听页面权限checkbox
                            form.on('checkbox(pauthId)', function(data){
                                if (data.elem.checked == true) {
                                    var isAllCheck = true;
                                    $(data.othis).parent().find("div.layui-form-checkbox").each(function () {
                                        if (!($(this).hasClass("layui-form-checked"))){
                                            isAllCheck = false;
                                        }
                                    });
                                    if (isAllCheck == true && !($(data.othis).parent().parent().prev().find("div.layui-form-checkbox").hasClass("layui-form-checked"))){
                                        $(data.othis).parent().parent().prev().find("input[name='mauthId']").prop("checked",true);
                                    }
                                } else {
                                    if ($(data.othis).parent().parent().prev().find("div.layui-form-checkbox").hasClass("layui-form-checked")){
                                        $(data.othis).parent().parent().prev().find("input[name='mauthId']").prop("checked",false);
                                    }
                                }
                                form.render("checkbox");
                            });



                            //全选
                            $("#check1").click(function (){
                                var el= document.getElementsByName("pauthId");
                                for (var i=0;i<el.length;i++) {
                                    if(el[i].checked == false) {
                                        el[i].checked=true;
                                    }else{
                                        el[i].checked=false;
                                    }
                                }
                                form.render('checkbox');
                            });


                            //表单校验
                            form.verify({
                                isExist:function(){
                                    var message = '';
                                    $.ajax({
                                        url: "queryByEmpId",
                                        dataType:'json',
                                        type: "post",
                                        async: false,
                                        data: {"empAccount":$("input[name=empAccount]").val()},
                                        success: function(result) {
                                            if(result){

                                            }else{
                                                message ="员工账号已存在，请重新输入！";
                                            }
                                        },
                                    });
                                    //需要注意 需要将返回信息写在ajax方法外
                                    if (message !== ''){
                                        return message;
                                    }
                                }
                            });

                            form.verify({
                                confirmPass:function(value){
                                    if($('input[name=empPassword]').val() != value) {
                                        return '两次密码输入不一致！';
                                    }
                                }
                            });

                            //监听提交
                            form.on('submit(insetEmp)', function(data){
                                var mauthIds = $("input:checked[name='mauthId']");
                                var pauthIds = $("input:checked[name='pauthId']");

                                data.field['mauthId'] = undefined;
                                data.field['pauthId'] = undefined;

                                var empModel = [];
                                for (var i = 0; i < mauthIds.length; i++) {
                                    empModel.push($(mauthIds[i]).val());
                                }
                                var empPage = [];
                                for (var i = 0; i < pauthIds.length; i++) {
                                    empPage.push($(pauthIds[i]).val());
                                }

                                $.ajax({
                                    type:"post"
                                    ,url:"saveEmp"
                                    ,dataType:"json"
                                    ,data:{
                                        empInfo: JSON.stringify(data.field),
                                        empPageAuthIds: JSON.stringify(empPage),
                                        empModelAuthIds: JSON.stringify(empModel)
                                    }
                                    ,success:function (data) {
                                        $(".page > .page-wrap").children().remove();
                                        $(".page > .page-wrap").load("/employee .page-empAll",function(){empAll()});
                                    }
                                })
                                return false;
                            });
                            form.render();
                        }
                    })
                });
            })
            //修改员工
            $("#updateEmp").click(function () {
                var checkStatus = layui.table.checkStatus('te').data;
                var ids = [];
                for(var i=0;i<checkStatus.length;i++){
                    ids.push(checkStatus[i].empAccount);
                }
                ids = ids.join(',');
                if (checkStatus.length == 0){
                    layer.confirm("请选择要修改的员工！");
                    return false;
                }else if (checkStatus.length > 1){
                    layer.confirm("请选择一行数据！");
                    return false;
                }
                if (ids != ''){
                    /* 加载修改员工页面*/
                    $.ajax({
                        type: "post"
                        , url: "pageModel"
                        , dataType: "json"
                        , success: function (data) {
                            $(".page > .page-wrap").children().remove();
                            $(".page > .page-wrap").load("/updateEmpPage .page-updateEmp", function (){

                                var modelAuthArr = {length: 0};
                                for (var i = 0; i < data.length; i++) {
                                    modelAuthArr['empModel' + data[i]['empModel']['mauthId']] = data[i]['empModel'];
                                    modelAuthArr['length'] += 1;
                                }

                                var authChecks = '';
                                var button = "";

                                var isFirst = true;
                                $.each(modelAuthArr, function (attrname, item) {

                                    if (attrname != 'length') {

                                        var tr = '<tr>';

                                        //判断是否有标题td列
                                        if (isFirst == true) {
                                            tr += '<td rowspan="' + modelAuthArr.length + '" class="class-title">页面权限:' +
                                                '<input type="button" value="权限全选" id="check1">' +
                                                '</td>';
                                            isFirst = false;
                                        }
                                        /*模块td列*/
                                        tr += '<td class="td-admin">'
                                            +'<input type="checkbox" lay-filter="mauthId" lay-skin="primary" name="mauthId" title="'+item['mauthName']+'" value="'+item['mauthId']+'"/>'
                                            +'</td>'

                                        //单个页面访问权限
                                        tr += '<td colspan="' + 8 + '" class="td-left"><div class="div-checkbox">'
                                        for (var i = 0; i < data.length; i++) {
                                            if (data[i]['pauthMauthId'] == item['mauthId']) {
                                                tr += '<input type="checkbox" lay-filter="pauthId" lay-skin="primary" title="' + data[i]['pauthName'] + '" value="' + data[i]['pauthId'] + '" name="pauthId"/>'
                                            }
                                        }

                                        tr += '</div></td>';
                                        tr += '</tr>';

                                        authChecks += tr;
                                    }
                                });

                                button += '<td colspan="' + 9 + '"><div class="td-left-button">'
                                    + '<button type="button"  id="save-Employee" class="layui-btn layui-btn-normal" lay-submit lay-filter="updateEmp">修改员工</button>' + '</div>'
                                    + '</td>';

                                $("table#emp-page").append(authChecks, button);

                                //加载分站下拉框
                                loadSubstList("empSubstId");

                                //监听模块权限checkbox
                                form.on('checkbox(mauthId)', function(data){
                                    if (data.elem.checked == true){
                                        $(data.othis).parent().next().find("div.div-checkbox > input[name='pauthId']").prop("checked",true);
                                    }else {
                                        $(data.othis).parent().next().find("div.div-checkbox > input[name='pauthId']").prop("checked",false);
                                    }
                                    form.render("checkbox");
                                });

                                //监听页面权限checkbox
                                form.on('checkbox(pauthId)', function(data){
                                    if (data.elem.checked == true) {
                                        var isAllCheck = true;
                                        $(data.othis).parent().find("div.layui-form-checkbox").each(function () {
                                            if (!($(this).hasClass("layui-form-checked"))){
                                                isAllCheck = false;
                                            }
                                        });
                                        if (isAllCheck == true && !($(data.othis).parent().parent().prev().find("div.layui-form-checkbox").hasClass("layui-form-checked"))){
                                            $(data.othis).parent().parent().prev().find("input[name='mauthId']").prop("checked",true);
                                        }
                                    } else {
                                        if ($(data.othis).parent().parent().prev().find("div.layui-form-checkbox").hasClass("layui-form-checked")){
                                            $(data.othis).parent().parent().prev().find("input[name='mauthId']").prop("checked",false);
                                        }
                                    }
                                    form.render("checkbox");
                                });

                                //全选
                                $("#check1").click(function (){
                                    var el= document.getElementsByName("pauthId");
                                    for (var i=0;i<el.length;i++) {
                                        if(el[i].checked == false) {
                                            el[i].checked=true;
                                        }else{
                                            el[i].checked=false;
                                        }
                                    }
                                    form.render('checkbox');
                                });

                                var empLoad = layer.load(1, {
                                    shade: [0.3, '#fff'], //0.1透明度的白色背景
                                });
                                /*根据id查询员工*/
                                $.ajax({
                                    type: "post"
                                    , url: "/queryByEmpAccount"
                                    , dataType: "json"
                                    , data: {empAccount: ids}
                                    , success: function (re) {
                                        console.log(re);

                                        var empModels = re['empModel'];
                                        for (var i = 0; i < empModels.length; i++) {
                                            $(".td-admin > input[name='mauthId'][value='"+empModels[i]['mauthId']+"']").each(function(){
                                                $(this).prop("checked","true");
                                            })
                                            $(".td-admin > input[name='mauthId'][value='"+empModels[i]['mauthId']+"']").parent().next().find(".div-checkbox > input[name='pauthId']").each(function(){
                                                $(this).prop("checked","true");
                                            })
                                        }
                                        var empPages = re['empPage'];
                                        for (var i = 0; i < empPages.length; i++) {
                                            $("td.td-left > div.div-checkbox > input[name='pauthId'][value='"+empPages[i]['pauthId']+"']").each(function(){
                                                $(this).prop("checked","true");
                                            })
                                        }


                                        var empSex = re.empSex;
                                        if (empSex == '女'){
                                            $("[name='empSex']").get(1).checked = true;
                                        }
                                        if (empSex == '男'){
                                            $("[name='empSex']").get(0).checked = true;
                                        }
                                        var empAccountStatus = re.empAccountStatus;
                                        if (empAccountStatus == 1){
                                            $("[name='empAccountStatus']").get(0).checked = true;
                                        }
                                        if (empAccountStatus == 2){
                                            $("[name='empAccountStatus']").get(1).checked = true;
                                        }
                                        var empDataAuth = re.empDataAuth;
                                        if (empDataAuth == 1){
                                            $("[name='empDataAuth']").get(0).checked = true;
                                        }
                                        if (empDataAuth == 2){
                                            $("[name='empDataAuth']").get(1).checked = true;
                                        }
                                        if (empDataAuth == 3){
                                            $("[name='empDataAuth']").get(2).checked = true;
                                        }

                                        $("input[name=empAccount]").val(re.empAccount)
                                        $("input[name=empPassword]").prop("disabled","disabled")
                                        $("input[name=empName]").val(re.empName)
                                        $("#up-subName").val(re.substName)
                                        $("input[name=empTelephone]").val(re.empTelephone)
                                        $("input[name=empJobnumber]").val(re.empJobnumber)
                                        $("input[name=empDepartment]").val(re.empDepartment)
                                        $("input[name=empWorkplace]").val(re.empWorkplace)
                                        $("input[name=empEducation]").val(re.empEducation)
                                        $("input[name=empSalary]").val(re.empSalary)
                                        $("input[name=empHomeAddress]").val(re.empHomeAddress)
                                        $("input[name=empHomePhone]").val(re.empHomePhone)
                                        $("input[name=empIdnumber]").val(re.empIdnumber)
                                        $("input[name=empBirhdate]").val(re.empBirhdate)
                                        $("input[name=empJoindate]").val(re.empJoindate)

                                        form.val("update-emp",{
                                            "empSubstId": re.empSubstId
                                        })

                                        form.render();
                                        layer.close(empLoad);
                                    }
                                });

                                //监听提交
                                form.on('submit(updateEmp)', function(data){
                                    var mauthIds = $("input:checked[name='mauthId']");
                                    var pauthIds = $("input:checked[name='pauthId']");

                                    data.field['mauthId'] = undefined;
                                    data.field['pauthId'] = undefined;
                                    data.field['empPassword'] = undefined;

                                    var empModel = [];
                                    for (var i = 0; i < mauthIds.length; i++) {
                                        empModel.push($(mauthIds[i]).val());
                                    }
                                    var empPage = [];
                                    for (var i = 0; i < pauthIds.length; i++) {
                                        empPage.push($(pauthIds[i]).val());
                                    }
                                    var empUpdateLoad = layer.load(1, {
                                        shade: [0.3, '#fff'], //0.1透明度的白色背景
                                    });
                                    $.ajax({
                                        type:"post"
                                        ,url:"updateEmp"
                                        ,dataType:"json"
                                        ,data:{
                                            empInfo: JSON.stringify(data.field),
                                            empPageAuthIds: JSON.stringify(empPage),
                                            empModelAuthIds: JSON.stringify(empModel)
                                        }
                                        ,success:function (data) {
                                            layer.close(empUpdateLoad);
                                            $(".page > .page-wrap").children().remove();
                                            $(".page > .page-wrap").load("/employee .page-empAll",function(){empAll()});
                                        }
                                    })
                                    return false;
                                });
                                form.render();
                            })
                        }
                    })
                }
            })

            //删除员工
            $("#deleteEmp").click(function () {
                //获得表格CheckBox已经选中的行的信息
                var checkStatus = table.checkStatus('te');
                //定义数组存放批量删除的行的id
                var listId = [];
                //获得所有选中行的数据
                var datas = checkStatus.data;
                //进行遍历所有选中行数据，拿出每一行的id存储到数组中
                $.each(datas, function (i,data) {
                    listId.push(data.empAccount);
                });
                if (listId.length <= 0) {
                    layer.msg("请选择要删除的行", {icon: 2})
                } else {
                    var confirmDel = layer.confirm('真的删除行么', function () {
                        $.ajax({
                            url: "/deleteEmp",
                            type: "post",
                            dataType: "json",
                            data:{"empAccount":listId.toString()},
                            success: function () {
                                $(".page > .page-wrap").children().remove();
                                $(".page > .page-wrap").load("/employee .page-empAll",function(){empAll()});
                                layer.close(confirmDel);
                                form.render();
                            }
                        });
                    });

                }
            })
        }

        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/employee .page-empAll", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            empAll();
        });
    });

    //分站管理
    $(".list-sys > .layui-nav-child > dd > a.nav-subst-list").click(function () {

        function subAll(){
            layui.use('table', function () {

                var table = layui.table;
                table.render({
                    id: 'tab'
                    ,elem: '#tab-fz'
                    , url: '/querySub'
                    , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                    , cols: [[
                        {type: 'checkbox',name:'test'}
                        ,{field: 'substId', width:120, title:'#',align:'center'}
                        , {field: 'substName', width: 130, title: '分站名称',align:'center'}
                        , {field: 'substTelephone', width: 150, title: '分站电话',align:'center'}
                        , {field: 'substAddress', title: '分站地址', width: 150,align:'center'}
                        , {field: 'substNnt', title: '分站人数', width: 120,align:'center'}
                        , {field: 'substPrincipal', width: 150, title: '负责人',align:'center'}
                        , {field: 'substPrincipalPhone', width: 150, title: '负责人手机',align:'center'}
                        , {field: 'right', width: 249, title: '操作',toolbar:'#toolbarDemo', align:'center'}
                    ]],
                });

                //监听行工具事件
                table.on('tool(tab-fz)', function(obj) {
                    var data = obj.data;
                    switch(obj.event){
                        case 'income':
                            // 财务结算 收入明细
                            $(".page > .page-wrap").children().remove();
                            $(".page > .page-wrap").load("/income .page-income",function (responseText,textStatus,XMLHttpRequest) {
                                var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
                                if (isNotAuth == false){
                                    return true;
                                }
                                //新增收入
                                $("#insertIncome").click(function () {
                                    layer.open({
                                        type: 1
                                        ,title: ['新增收入💴', 'font-size:18px;background-color: #38b4ee;']
                                        ,closeBtn: 1
                                        ,area: '900px;'
                                        ,shade: 0.8
                                        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                                        ,btnAlign: 'c'
                                        ,moveType: 1 //拖拽模式，0或者1
                                        ,content: '<form class="layui-form" action="" lay-filter="example">' +
                                            '<div class="insertIncome-from">\n' +
                                            '      <div class="input-group">\n' +
                                            '        <table class="insertIncome-table"  >\n' +
                                            '            <tr style="text-align: center">\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon1">录入日期</span>\n' +
                                            '                    <input type="date" name="incomeEnteringDate" class="form-control" id="insertIncomeTime" aria-describedby="basic-addon1">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon2">操作站点</span>\n' +
                                            '                    <input type="text" name="incomeSubstId" id="incomeSubstId" readonly="readonly" class="form-control" aria-describedby="basic-addon1">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon3">所属部门</span>\n' +
                                            '                    <input type="text" name="incomeDepartment" value="哈哈" readonly="readonly" class="form-control"  aria-describedby="basic-addon1">\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon4">收入科目</span>\n' +
                                            '                    <select class="form-control" id="exampleFormControlSelect1" name="incomeCourse">\n' +
                                            '                        <option value="" selected="selected">请选择</option>\n' +
                                            '                        <option value=\'营业收入\'>营业收入</option>                                                                                                  ";\n' +
                                            '                        <option value=\'营业外收入\'>营业外收入</option>                                                                                                  ";                                                                                      ";\n' +
                                            '                        <option value=\'运营开支\'>运营开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'行政开支\'>行政开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'办公开支\'>办公开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'出差开支\'>出差开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'人员工资\'>人员工资</option>                                                                                                  ";\n' +
                                            '                        <option value=\'运输开支\'>运输开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'派送开支\'>派送开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'外包开支\'>外包开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'提货开支\'>提货开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'其他开支\'>其他开支</option>\n' +
                                            '                    </select>\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon5">收入金额</span>\n' +
                                            '                    <input type="text" class="form-control" name="incomeCredit" aria-describedby="basic-addon1">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon6">收入方式</span>\n' +
                                            '                    <select class="form-control" id="exampleFormControlSelect2" name="incomeWay">\n' +
                                            '                        <option value="" selected="selected">请选择</option>\n' +
                                            '                        <option value="现金支付">现金支付</option>\n' +
                                            '                        <option value="公司转账">公司转账</option>\n' +
                                            '                        <option value="微信">微信</option>\n' +
                                            '                        <option value="支付宝">支付宝</option>\n' +
                                            '                    </select>\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon7">收入内容</span>\n' +
                                            '                    <input type="text" class="form-control"  aria-describedby="basic-addon1" name="incomeContent">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon8">凭证号</span>\n' +
                                            '                    <input type="text" class="form-control" aria-describedby="basic-addon1" name="incomeVoucherNum">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon9">付款对象</span>\n' +
                                            '                    <input type="text" class="form-control"  aria-describedby="basic-addon1" name="incomePayObj">\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon11">收支类型</span>\n' +
                                            '                    <select class="form-control" id="exampleFormControlSelect3" name="incomeType">\n' +
                                            '                        <option value="" selected="selected">请选择</option>\n' +
                                            '                        <option value="出港费用">出港费用</option>\n' +
                                            '                        <option value="进港费用">进港费用</option>\n' +
                                            '                    </select>\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon12">进港站点</span>\n' +
                                            '                    <input type="text" class="form-control" aria-describedby="basic-addon1" name="incomeArrivalStation">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon13">录入员</span>\n' +
                                            '                    <input type="text" readonly="readonly" class="form-control"  aria-describedby="basic-addon1" name="incomeTypeinPerson">\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td style="border: 0px solid #d9edf7;">\n' +
                                            '                    <i class="table-i">备注：</i>\n' +
                                            '                    <textarea class="table-textarea" placeholder="请输入内容" style="width:200px;height: 50px" name="incomeRemark"></textarea>\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td style="border: 0px solid #d9edf7;">\n' +
                                            '                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="insertIncome" style="background-color: #1E9FFF">确定</button>\n' +
                                            '                    <button type="button" class="layui-btn layui-btn-primary">取消</button>\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '        </table>\n' +
                                            '    </div>' +
                                            '</div>' +
                                            '</from>'
                                        ,success: function(){
                                            $.ajax({
                                                type: "POST",
                                                url: "/getLoginedEmp",
                                                success: function (data) {
                                                    $("input[name='incomeSubstId']").val(data['empSubstId']);
                                                    $("input[name='incomeDepartment']").val(data['empDepartment']);
                                                    $("input[name='incomeTypeinPerson']").val(data['empName']);//录入员
                                                }
                                            });
                                            //获取系统当前时间
                                            $(document).ready(function () {
                                                var time = new Date();
                                                var day = ("0" + time.getDate()).slice(-2);
                                                var month = ("0" + (time.getMonth() + 1)).slice(-2);
                                                var today = time.getFullYear() + "-" + (month) + "-" + (day);
                                                $('#insertIncomeTime').val(today);
                                            })
                                            form.on('submit(insertIncome)', function(data){
                                                $.ajax({
                                                    contentType: "application/json;charset=UTF-8",
                                                    type: "post",
                                                    url: "/addIncome",
                                                    dataType: "json",
                                                    data: JSON.stringify(data.field),
                                                    success: function (data) {
                                                        //新增收支明细
                                                        $.ajax({
                                                            contentType: "application/json;charset=UTF-8",
                                                            type: "post",
                                                            url: "/addIncome",
                                                            dataType: "json",
                                                            data: JSON.stringify(data.field),
                                                            success: function (data) {
                                                            }
                                                        })
                                                        layer.msg(data['msg'], {icon: 6, time: 1400});
                                                        parent.layer.close(1);
                                                        table.reload('selectAllIncome', {
                                                            page: {
                                                                curr: 1
                                                            }
                                                        });
                                                    }
                                                })
                                                return false;
                                            });
                                        }
                                    });

                                })
                                laydate.render({
                                    elem: '#begin'
                                    ,theme: 'grid'
                                });
                                laydate.render({
                                    elem: '#end'
                                    ,theme: 'grid'
                                });
                                var incomeTable = layui.use('table', function(){
                                    //根据条件查询
                                    form.on('submit(selectIncomeByCondition)', function(data){
                                        data.field['page'] = incomeTable['config']['page']['curr'];
                                        data.field['count'] = incomeTable['config']['page']['count'];
                                        data.field['limit'] = incomeTable['config']['page']['limit'];
                                        table.reload('selectAllIncome', {
                                            method: "post"
                                            , url: "/selectIncomeByCondition"
                                            , where: {
                                                financeCondition: JSON.stringify(data.field)
                                            }
                                            , page: {
                                                curr: 1 //重新从第 1 页开始
                                            }
                                        });
                                        return false;
                                    });
                                    var table = layui.table;
                                    table.render({
                                        elem: '#selectAllIncome'
                                        ,url:'/selectAllIncome'
                                        , width: 1660
                                        , height: 380
                                        , id:'selectAllIncome'
                                        ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                                            layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                                            //,curr: 5 //设定初始在第 5 页
                                            ,groups: 1 //只显示 1 个连续页码
                                            ,first: false //不显示首页
                                            ,last: false //不显示尾页
                                        }
                                        ,cols: [[
                                            {type:'numbers',title:"序号"}
                                            ,{templet:'<div>{{d.finance.inspendFound}}</div>', title:'资金项目',width:90}//  收支明细表
                                            ,{field:'incomeCredit', title:'收入金额',width:90}
                                            ,{field:'incomeCourse', title:'收支科目' ,width:105}
                                            ,{field:'incomeType', title: '收支类型',width:90}
                                            ,{field:'incomeWay', title:'收支方式',width:90}
                                            ,{field:'incomeArrivalStation', title:'进港站点',width:90}
                                            ,{field:'incomeSubstId', title:'发生站点',width:90}//
                                            ,{field:'incomeContent', title:'收支内容',width:110}
                                            ,{field:'incomeTypeinPerson', title:'操作员',width:90}
                                            ,{field:'incomePayObj', title:'付款对象',width:90}
                                            ,{field:'incomeRemark', title:'备注',width:150}
                                            ,{templet:'<div>{{d.finance.inspendPersonCheck}}</div>', title:'个人审核',width:90}// //  收支明细表inspendPersonCheck
                                            ,{templet:'<div>{{d.finance.inspendVerifier}}</div>', title:'审核人',width:90}////  收支明细表inspendVerifier
                                            ,{templet:'<div>{{d.finance.inspendSubstationCheck}}</div>', title:'分站审核',width:90}////  收支明细表inspendSubstationCheck
                                            ,{templet:'<div>{{d.finance.inspendSubstationVerifier}}</div>',title:'分站审核人',width:110}////  收支明细表inspendSubstationVerifier
                                            ,{field:'incomeVoucherNum', title:'凭证号',width:120}
                                        ]]

                                    });
                                });
                            })
                            form.render();
                            break;
                        case 'spending':
                            // 财务结算 开支明细
                            $(".page > .page-wrap").children().remove();
                            $(".page > .page-wrap").load("/spend .page-income",function () {
                                $.ajax({
                                    type: "POST",
                                    url: "/getSubstationListFS",
                                    success: function(data){
                                        for (var i = 0; i < data.length; i++) {
                                            var li = "<option value='"+data[i]['substName']+"'>"+data[i]['substName']+"</option>"
                                            $("select[name='financeOccurStation']").append(li);
                                        }
                                    }
                                });
                                //新增开支
                                $("#insertIncome").click(function () {

                                    var SpendOpen = layer.open({
                                        type: 1
                                        ,title: ['新增开支💴', 'font-size:18px;background-color: #38b4ee;']
                                        ,closeBtn: 1
                                        ,area: '900px;'
                                        ,shade: 0.8
                                        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                                        ,btnAlign: 'c'
                                        ,moveType: 1 //拖拽模式，0或者1
                                        ,content: '<form class="layui-form" action="" lay-filter="example">' +
                                            '<div class="insertIncome-from">\n' +
                                            '      <div class="input-group">\n' +
                                            '        <table class="insertIncome-table"  >\n' +
                                            '            <tr style="text-align: center">\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon1">录入日期</span>\n' +
                                            '                    <input type="date" name="spendEnteringDate" class="form-control" id="insertIncomeTime" aria-describedby="basic-addon1">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon2">操作站点</span>\n' +
                                            '                    <input type="text" name="spendSubstId" id="spendSubstId" readonly="readonly" class="form-control" aria-describedby="basic-addon1">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon3">所属部门</span>\n' +
                                            '                    <input type="text" name="spendDepartment" readonly="readonly" class="form-control"  aria-describedby="basic-addon1">\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon4">开支科目</span>\n' +
                                            '                    <select class="form-control" id="exampleFormControlSelect1" name="spendCourse">\n' +
                                            '                        <option value="" selected="selected">请选择</option>\n' +
                                            '                                                                                                                         ";                                                                                      ";\n' +
                                            '                        <option value=\'运营开支\'>运营开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'行政开支\'>行政开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'办公开支\'>办公开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'出差开支\'>出差开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'人员工资\'>人员工资</option>                                                                                                  ";\n' +
                                            '                        <option value=\'运输开支\'>运输开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'派送开支\'>派送开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'外包开支\'>外包开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'提货开支\'>提货开支</option>                                                                                                  ";\n' +
                                            '                        <option value=\'其他开支\'>其他开支</option>\n' +
                                            '                    </select>\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon5">支出金额</span>\n' +
                                            '                    <input type="text" class="form-control" name="spendDebit" aria-describedby="basic-addon1">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon6">开支方式</span>\n' +
                                            '                    <select class="form-control" id="exampleFormControlSelect2" name="spendWay">\n' +
                                            '                        <option value="" selected="selected">请选择</option>\n' +
                                            '                        <option value="现金支付">现金支付</option>\n' +
                                            '                        <option value="公司转账">公司转账</option>\n' +
                                            '                        <option value="微信">微信</option>\n' +
                                            '                        <option value="支付宝">支付宝</option>\n' +
                                            '                    </select>\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon7">开支内容</span>\n' +
                                            '                    <input type="text" class="form-control"  aria-describedby="basic-addon1" name="spendContent">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon8">凭证号</span>\n' +
                                            '                    <input type="text" class="form-control" aria-describedby="basic-addon1" name="spendVoucherNum">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon9">付款对象</span>\n' +
                                            '                    <input type="text" class="form-control"  aria-describedby="basic-addon1" name="spendPayObj">\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon11">开支类型</span>\n' +
                                            '                    <select class="form-control" id="exampleFormControlSelect3" name="spendType">\n' +
                                            '                        <option value="" selected="selected">请选择</option>\n' +
                                            '                        <option value="出港费用">出港费用</option>\n' +
                                            '                        <option value="进港费用">进港费用</option>\n' +
                                            '                    </select>\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon"' +
                                            'id="basic-addon12">进港站点</span>\n' +
                                            '                    <input type="text" class="form-control" aria-describedby="basic-addon1" name="spendArrivalStation">\n' +
                                            '                </td>\n' +
                                            '                <td>\n' +
                                            '                    <span class="input-group-addon" id="basic-addon13">录入员</span>\n' +
                                            '                    <input type="text" readonly="readonly" class="form-control"  aria-describedby="basic-addon1" name="spendTypeinPerson">\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td style="border: 0px solid #d9edf7;">\n' +
                                            '                    <i class="table-i">备注：</i>\n' +
                                            '                    <textarea class="table-textarea" placeholder="请输入内容" style="width:200px;height: 50px" name="spendRemark"></textarea>\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '            <tr>\n' +
                                            '                <td style="border: 0px solid #d9edf7;">\n' +
                                            '                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="insertSpend" style="background-color: #1E9FFF">确定</button>\n' +
                                            '                    <button type="button" class="layui-btn layui-btn-primary">取消</button>\n' +
                                            '                </td>\n' +
                                            '            </tr>\n' +
                                            '        </table>\n' +
                                            '    </div>' +
                                            '</div>' +
                                            '</from>'
                                        ,success: function(){
                                            $.ajax({
                                                type: "POST",
                                                url: "/getLoginedEmp",
                                                success: function (data) {
                                                    $.ajax({
                                                        type: "POST",
                                                        url: "/selectSubNameById",
                                                        data:{empSubstId:data.empSubstId},
                                                        dataType:"text",
                                                        success: function (data) {
                                                            $("input[name='spendSubstId']").val(data);
                                                        }
                                                    });
                                                    $("input[name='spendDepartment']").val(data['empDepartment']);
                                                    $("input[name='spendTypeinPerson']").val(data['empName']);//录入员
                                                }
                                            });
                                            //获取系统当前时间
                                            $(document).ready(function () {
                                                var time = new Date();
                                                var day = ("0" + time.getDate()).slice(-2);
                                                var month = ("0" + (time.getMonth() + 1)).slice(-2);
                                                var today = time.getFullYear() + "-" + (month) + "-" + (day);
                                                $('#insertIncomeTime').val(today);
                                            })
                                            form.on('submit(insertSpend)', function(data){
                                                $.ajax({
                                                    contentType: "application/json;charset=UTF-8",
                                                    type: "post",
                                                    url: "/addSpend",
                                                    dataType: "json",
                                                    data: JSON.stringify(data.field),
                                                    success: function (data) {
                                                        layer.msg(data['msg'], {icon: 6, time: 1400});
                                                        parent.layer.close(SpendOpen)
                                                        table.reload('selectAllSpend', {
                                                            page: {
                                                                curr: 1
                                                            }
                                                        });
                                                    }
                                                })
                                                return false;
                                            });
                                        }
                                    });

                                })

                                laydate.render({
                                    elem: '#begin'
                                    ,theme: 'grid'
                                });
                                laydate.render({
                                    elem: '#end'
                                    ,theme: 'grid'
                                });
                                layui.use('table', function(){
                                    //根据条件查询
                                    form.on('submit(selectSpendByCondition)', function(data){
                                        data.field['page'] = spendTable['config']['page']['curr'];
                                        data.field['count'] = spendTable['config']['page']['count'];
                                        data.field['limit'] = spendTable['config']['page']['limit'];
                                        table.reload('selectAllSpend', {
                                            method: "post"
                                            , url: "/selectSpendByCondition"
                                            , where: {
                                                financeCondition: JSON.stringify(data.field)
                                            }
                                            , page: {
                                                curr: 1 //重新从第 1 页开始
                                            }
                                        });
                                        return false;
                                    });
                                    var table = layui.table;
                                    var spendTable = table.render({
                                        elem: '#selectAllSpend'
                                        ,url:'/selectAllSpend'
                                        , width: 1760
                                        , height: 380
                                        , id:'selectAllSpend'
                                        ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                                            //,curr: 5 //设定初始在第 5 页
                                            groups: 1 //只显示 1 个连续页码
                                            ,first: false //不显示首页
                                            ,last: false //不显示尾页
                                        }
                                        ,cols: [[
                                            {type:'numbers',title:"序号"}
                                            ,{templet:'<div>{{d.finance.inspendFound}}</div>', title:'资金项目',width:90}//  收支明细表
                                            ,{field:'spendEnteringDate', title:'开支日期',width:110}
                                            ,{field:'spendDebit', title:'支出金额',width:90}
                                            ,{field:'spendCourse', title:'开支科目' ,width:105}
                                            ,{field:'spendType', title: '开支类型',width:90}
                                            ,{field:'spendWay', title:'开支方式',width:90}
                                            ,{field:'spendArrivalStation', title:'进港站点',width:90}
                                            ,{field:'spendContent', title:'开支内容',width:110}
                                            ,{field:'spendTypeinPerson', title:'操作员',width:90}
                                            ,{field:'spendPayObj', title:'付款对象',width:90}
                                            ,{field:'spendRemark', title:'备注',width:150}
                                            ,{templet:'<div>{{d.finance.inspendPersonCheck}}</div>', title:'个人审核',width:90}// //  收支明细表inspendPersonCheck
                                            ,{templet:'<div>{{d.finance.inspendVerifier}}</div>', title:'审核人',width:90}////  收支明细表inspendVerifier
                                            ,{templet:'<div>{{d.finance.inspendSubstationCheck}}</div>', title:'分站审核',width:90}////  收支明细表inspendSubstationCheck
                                            ,{templet:'<div>{{d.finance.inspendSubstationVerifier}}</div>',title:'分站审核人',width:110}////  收支明细表inspendSubstationVerifier
                                            ,{field:'spendVoucherNum', title:'凭证号',width:120}
                                        ]]

                                    });
                                });
                            })
                            break;
                        case 'waybill':
                            //运单管理
                            $(".page > .page-wrap").children().remove();
                            $(".page > .page-wrap").load("/waybillList .page-this", function (responseText,textStatus,XMLHttpRequest) {
                                var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
                                if (isNotAuth == false){
                                    return true;
                                }
                                laydate.render({ //起止日期，日期下拉框
                                    elem: '#start-end-date'
                                    , range: '~' //或 range: '~' 来自定义分割字符
                                    , theme: "#5974d9"
                                });
                                //加载分站下拉框
                                loadSubstList(["waybillStartingSubst", "waybillReachSubst"]);
                                //表单的监听提交，运单搜索
                                form.on('submit(waybill-search)', function (data) {
                                    if (data.field['startEndDate'] != "") {
                                        var startEndDate = data.field['startEndDate'];
                                        var startEndDateArr = startEndDate.split("~");
                                        var startDate = startEndDateArr[0].trim();
                                        var endDate = startEndDateArr[1].trim();
                                        data.field['startDate'] = startDate;
                                        data.field['endDate'] = endDate;
                                    }
                                    data.field['startEndDate'] = undefined;

                                    data.field['page'] = waybillTable['config']['page']['curr'];
                                    data.field['count'] = waybillTable['config']['page']['count'];

                                    table.reload('waybill-info', {
                                        method: "post"
                                        , url: "queryWaybillConditionLayui"
                                        , where: {waybillCondition: JSON.stringify(data.field)}
                                        , page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                    });
                                    return false;
                                });
                                form.render();

                                //运单表格实例
                                var waybillTable = table.render({
                                    elem: '#waybill-info'
                                    , id: "waybill-info"
                                    , height: 400
                                    , url: '/queryWaybillLimitLayui' //数据接口
                                    , request: {
                                        pageName: 'page' //页码的参数名称，默认：page
                                        , limitName: 'limit' //每页数据量的参数名，默认：limit
                                    }
                                    , page: true //开启分页
                                    , cols: [[ //表头
                                        {type: 'checkbox', fixed: 'left'}
                                        , {type: 'numbers', title: "序号"}
                                        , {field: 'waybillConsignNum', title: '托运单号', width: 220, sort: true}
                                        , {field: 'waybillConsignDate', title: '托运日期', width: 120}
                                        , {field: 'shipperCom', title: '发货单位', width: 170}
                                        , {field: 'startingSubst', title: '出发分站', width: 170}
                                        , {field: 'reachSubst', title: '到达分站', width: 170, sort: true}
                                        , {field: 'waybillReachCity', title: '到达城市', width: 170}
                                        , {field: 'trackType', title: '运单状态', width: 135,
                                            templet:function (d) {
                                                var trackType = d.trackType;
                                                var content = "";
                                                switch (trackType) {
                                                    case 1:
                                                        content = "收件入库";
                                                        break;
                                                    case 2:
                                                        content = "已装车";
                                                        break;
                                                    case 3:
                                                        content = "正在运输";
                                                        break;
                                                    case 4:
                                                        content = "转运";
                                                        break;
                                                    case 5:
                                                        content = "正在派送";
                                                        break;
                                                    case 6:
                                                        content = "已签收";
                                                }
                                                return content;
                                            }
                                        }
                                        , {field: 'waybillTransType', title: '运输类型', width: 135, sort: true}
                                        , {field: 'waybillCargoName', title: '货物名称', width: 135, sort: true}
                                        , {field: 'waybillPromiseDate', title: '承诺时间', width: 135, sort: true}
                                        , {field: 'trackDate', title: '签收时间', width: 135, sort: true}
                                        , {field: 'waybillCargoCount', title: '数量', width: 135, sort: true}
                                        , {field: 'waybillPackingWay', title: '包装', width: 135, sort: true}
                                        , {field: 'waybillCargoWeight', title: '重量/kg', width: 135, sort: true}
                                        , {field: 'waybillCargoVolume', title: '体积/m³', width: 135, sort: true}
                                        , {field: 'waybillCargoPrice', title: '单价', width: 135, sort: true}
                                        , {field: 'waybillBasicFreight', title: '基本运费', width: 135, sort: true}
                                        , {field: 'waybillPickupFee', title: '提货费', width: 135, sort: true}
                                        , {field: 'waybillDeliveryFee', title: '送货费', width: 135, sort: true}
                                        , {field: 'waybillCargoValue', title: '货物价值', width: 135, sort: true}
                                        , {field: 'waybillInsuranceFee', title: '保费', width: 135, sort: true}
                                        , {field: 'waybillIncomeTotal', title: '费用合计', width: 135, sort: true}
                                        , {field: 'waybillNowIncome', title: '现付', width: 135, sort: true}
                                        , {field: 'waybillPaymentMethod', title: '付款方式', width: 135, sort: true}
                                        , {field: 'waybillReachPay', title: '到付', width: 135, sort: true}
                                        , {
                                            title: '到付状态', width: 135, sort: true
                                            , templet: function (d) {
                                                return d.waybillReachPay ? '未付' : '';
                                            }
                                        }
                                        , {field: 'waybillBackpayMonth', title: '回付', width: 135, sort: true}
                                        , {
                                            title: '回付状态', width: 135, sort: true
                                            , templet: function (d) {
                                                return d.waybillBackpayMonth ? '未付' : '';
                                            }
                                        }
                                        , {field: 'shipperPerson', title: '发货人', width: 135, sort: true}
                                        , {field: 'shipperTelephone', title: '发货电话', width: 135, sort: true}
                                        , {field: 'shipperAddress', title: '发货地址', width: 170, sort: true}
                                        , {field: 'consiCom', title: '收货单位', width: 170, sort: true}
                                        , {field: 'consiPerson', title: '收货人', width: 135, sort: true}
                                        , {field: 'consiTelephone', title: '电话', width: 135, sort: true}
                                        , {field: 'consiAddress', title: '收货地址', width: 135, sort: true}
                                        , {field: 'consiRemark', title: '备注', width: 135, sort: true}
                                        , {field: 'transNum', title: '运输单号', width: 135, sort: true}
                                        , {field: 'transCarNumber', title: '运输车号', width: 135, sort: true}
                                        , {field: 'carDriver', title: '司机姓名', width: 135, sort: true}
                                        , {field: 'carDriverPhone', title: '司机手机', width: 135, sort: true}
                                        , {field: 'waybillPromoter', title: '业务员', width: 135, sort: true}
                                        , {field: 'empName', title: '开单员', width: 135, sort: true}
                                    ]]
                                });


                                /*运单作废*/
                                $(".waybill-list-btn-group .delete-waybill").click(function () {
                                    var checkStatus = table.checkStatus('waybill-info');//获取数据表格的选中状态

                                    var waybillConsignNumS = [];
                                    for (var i = 0; i < checkStatus.data.length; i++) {
                                        waybillConsignNumS.push(checkStatus.data[i]['waybillConsignNum']);
                                    }

                                    console.log(checkStatus);
                                    if (checkStatus.data.length == 0) {
                                        layer.msg('请先选中需要取消的运单！', {
                                            anim: 6
                                            , time: 2000
                                        });
                                    } else {
                                        layer.open({
                                            type: 0,
                                            title: "温馨提示",
                                            content: "您确定要取消所选的运单吗？",
                                            btn: ['确定','取消'],
                                            yes:function(){
                                                var index = layer.load(1, {
                                                    shade: [0.3, '#fff'], //0.1透明度的白色背景
                                                });

                                                //根据托运单号删除对应运单信息
                                                $.ajax({
                                                    url: "/cancelWaybillByConsignNumS",
                                                    contentType: "application/json;charset=UTF-8",
                                                    type: "POST",
                                                    dataType: "json",
                                                    data: JSON.stringify(waybillConsignNumS),
                                                    success: function (data) {
                                                        console.log(data);
                                                        layer.close(index);
                                                        if (data['result'] == "success") {
                                                            layer.msg(data['msg'], {icon: 6, time: 2000});
                                                            table.reload('waybill-info');
                                                        } else {
                                                            layer.msg(data['msg'], {icon: 0, time: 2000});
                                                        }

                                                    }
                                                });
                                            }
                                        });
                                    }

                                });


                                /*修改运单*/
                                $(".waybill-list-btn-group .update-waybill").click(function () {
                                    var checkStatus = table.checkStatus('waybill-info');//获取数据表格的选中状态
                                    if (checkStatus.data.length == 0) {
                                        layer.msg('请先选中需要修改的运单！', {
                                            anim: 6
                                            , time: 2000
                                        });
                                    } else if (checkStatus.data.length > 1) {
                                        layer.msg('只能选择一个运单修改！', {
                                            anim: 6
                                            , time: 2000
                                        });
                                    } else {

                                        //根据托运单号查询对应运单信息
                                        $.ajax({
                                            url: "/queryWaybillById",
                                            type: "POST",
                                            data: {
                                                waybillConsignNum: checkStatus.data[0]['waybillConsignNum']
                                            },
                                            success: function (data) {
                                                console.log(data);
                                                $(".page > .page-wrap").children().remove();
                                                $(".page > .page-wrap").load("/goUpdatewaybill .page-this-updatewaybill", function () {

                                                    //刷新表单到达站、出发站的下拉列表
                                                    loadSubstList(["waybillStartingSubst", "waybillReachSubst"]);

                                                    //加载发货方下拉列表和发货方下拉列表
                                                    loadShipperList();
                                                    loadConsiList();

                                                    //加载开单员，即当前登录用户
                                                    loadNowLoginEmpInfo();

                                                    layer.load(1, {
                                                        shade: [0.3, '#fff'], //0.1透明度的白色背景
                                                        time: 1000,
                                                        end: function () {
                                                            laydate.render({ //托运时间
                                                                elem: '#shipping-date', //指定元素
                                                                theme: "#5974d9"
                                                            });
                                                            laydate.render({ //承诺日期
                                                                elem: '#promise-date', //指定元素
                                                                theme: "#5974d9"
                                                            });

                                                            form.val("update-waybill-form", {
                                                                waybillBackpayMonth: data['waybillBackpayMonth'],
                                                                waybillBasicFreight: data['waybillBasicFreight'],
                                                                waybillBillingPerson: data['waybillBillingPerson'],
                                                                waybillCargoCount: data['waybillCargoCount'],
                                                                waybillCargoName: data['waybillCargoName'],
                                                                waybillCargoPrice: data['waybillCargoPrice'],
                                                                waybillCargoValue: data['waybillCargoValue'],
                                                                waybillCargoVolume: data['waybillCargoVolume'],
                                                                waybillCargoWeight: data['waybillCargoWeight'],
                                                                waybillChargeMode: data['waybillChargeMode'],
                                                                waybillConsiId: data['waybillConsiId'],
                                                                waybillConsignDate: data['waybillConsignDate'],
                                                                waybillConsignNum: data['waybillConsignNum'],
                                                                waybillDeliveryFee: data['waybillDeliveryFee'],
                                                                waybillIncomeTotal: data['waybillIncomeTotal'],
                                                                waybillInsuranceFee: data['waybillInsuranceFee'],
                                                                waybillNowIncome: data['waybillNowIncome'],
                                                                waybillOrderNum: data['waybillOrderNum'],
                                                                waybillOther: data['waybillOther'],
                                                                waybillPackingWay: data['waybillPackingWay'],
                                                                waybillPaymentMethod: data['waybillPaymentMethod'],
                                                                waybillPickupDriver: data['waybillPickupDriver'],
                                                                waybillPickupFee: data['waybillPickupFee'],
                                                                waybillPickupSpend: data['waybillPickupSpend'],
                                                                waybillPromiseDate: data['waybillPromiseDate'],
                                                                waybillPromoter: data['waybillPromoter'],
                                                                waybillReachCity: data['waybillReachCity'],
                                                                waybillReachPay: data['waybillReachPay'],
                                                                waybillReachSubst: data['waybillReachSubst'],
                                                                waybillRebateCollection: data['waybillRebateCollection'],
                                                                waybillReceipt: data['waybillReceipt'],
                                                                waybillRemark: data['waybillRemark'],
                                                                waybillShipperId: data['waybillShipperId'],
                                                                waybillShippingMethod: data['waybillShippingMethod'],
                                                                waybillSignforMess: data['waybillSignforMess'],
                                                                waybillStartingSubst: data['waybillStartingSubst'],
                                                                waybillTransType: data['waybillTransType'],
                                                                waybillUploadFee: data['waybillUploadFee']
                                                            });

                                                            form.on('submit(saveUpdateWaybill)', function (data) {
                                                                var waybillData = data.field;
                                                                console.log(data.field);

                                                                $.ajax({
                                                                    type: "POST",
                                                                    contentType: "application/json;charset=UTF-8",
                                                                    url: "/updateWaybill",
                                                                    dataType: "json",
                                                                    data: JSON.stringify(data.field),
                                                                    success: function (data) {
                                                                        console.log(data);
                                                                        layer.msg(data['msg'], {icon: 6, time: 1400});
                                                                        if (data['result'] == "success") {

                                                                        } else {

                                                                        }
                                                                    }
                                                                });

                                                                return false;
                                                            });
                                                            form.render();
                                                        }
                                                    });


                                                });


                                            }
                                        });
                                    }
                                });


                                //查看运单详情页面
                                /*table.on('rowDouble(waybill-info)', function (obj) {
                                    var data = obj.data;
                                    $(".page > .page-wrap").children().remove();
                                    $(".page > .page-wrap").load("/waybilldetail .page-this", function () {

                                    });
                                });*/

                            });
                            break;
                    };
                })
            });

            //新增分站
            $("#insertSub").click(function () {
                $(".page > .page-wrap").children().remove();
                $(".page > .page-wrap").load("/addSubPage .page-addSub", function () {
                    bindingSelect();
                    $("#province").on("change", function () {
                        chooseProvince($(this).get(0))
                    });
                    $("#city").on("change", function () {
                        chooseCity($(this).get(0));
                    });

                    //新增保存 表单校验
                    $("#sub-save").click(function () {

                        var substName = document.forms["myForm"]["substName"].value;
                        if (substName == null || substName == "") {
                            layer.msg('分站名称不能为空！', {icon: 5});
                            return false;
                        }

                        var substNnt = document.forms["myForm"]["substNnt"].value;
                        if (substNnt == null || substNnt == "") {
                            layer.msg('分站人数不能为空！', {icon: 5});
                            return false;
                        }

                        var substDetailAddress = $("#province").val() + $("#city").val() + $("#area").val()
                        $.ajax({
                            type: "post",
                            url: "/addSub",
                            dataType: "json",
                            data: {
                                substName: $("input[name=substName]").val(),
                                substTelephone: $("input[name=substTelephone]").val(),
                                substAddress: $("input[name=substAddress]").val(),
                                substDetailAddress: substDetailAddress,
                                substProperty: $("#substProperty").val(),
                                substPrincipal: $("input[name=substPrincipal]").val(),
                                substPrincipalPhone: $("input[name=substPrincipalPhone]").val(),
                                substNnt: $("input[name=substNnt]").val(),
                                substRemark: $("input[name=substRemark]").val(),
                                substOperator: $("input[name=substOperator]").val(),
                                substSendcity: $("#substSendcity").val(),
                            },
                            success: function (data) {
                                if (data = 1) {
                                    $(".page > .page-wrap").children().remove();
                                    $(".page > .page-wrap").load("/subAll .page-subAll",function(){subAll()});
                                    form.render();
                                }
                            }
                        });

                    });
                    //返回列表
                    $("#returnList").click(function () {
                        $(".page > .page-wrap").children().remove();
                        $(".page > .page-wrap").load("/subAll .page-subAll",function(){subAll()});
                    })

                });
            })
            //根据id查询
            $("#update-sub").click(function () {
                var checkStatus = layui.table.checkStatus('tab').data;
                var ids = [];
                for(var i=0;i<checkStatus.length;i++){
                    ids.push(checkStatus[i].substId);
                }
                ids = ids.join(',');
                if (checkStatus.length == 0){
                    layer.confirm("请选择要修改的员工！");
                    return false;
                }
                if (ids != ''){
                    var substDetailAddress = $("#province").val() + $("#city").val() + $("#area").val()
                    $.ajax({
                        type: "post",
                        url: "/queryById",
                        dataType: "json",
                        data: {"substId": ids},
                        success: function (data) {
                            $(".page > .page-wrap").children().remove();
                            $(".page > .page-wrap").load("/updadeSub .update-sub", function () {

                                bindingSelect();
                                $("#province").on("change", function () {
                                    chooseProvince($(this).get(0))
                                });
                                $("#city").on("change", function () {
                                    chooseCity($(this).get(0));
                                });

                                $("#substId").val(data.substId);
                                $("#substName").val(data.substName);
                                $("#substTelephone").val(data.substTelephone);
                                $("#substAddress").val(data.substAddress);
                                $("substDetailAddress").val(substDetailAddress);
                                $("#substPrincipal").val(data.substPrincipal);
                                $("#substPrincipalPhone").val(data.substPrincipalPhone);
                                $("#substNnt").val(data.substNnt);
                                $("#substRemark").val(data.substRemark);
                                $("#substOperator").val(data.substOperator);
                                $("#substSendcity").val(data.substSendcity);


                                $("#update-save").click(function () {
                                    $.ajax({
                                        type: "post",
                                        url: "/updateSubst",
                                        dataType: "json",
                                        data: $("#pageUpdateSub").serializeArray(),
                                        success: function (date) {
                                            $(".page > .page-wrap").children().remove();
                                            $(".page > .page-wrap").load("/subAll .page-subAll",function(){subAll()});
                                        }
                                    })
                                })
                            });
                        }
                    })
                }

                //返回列表
                $("#returnUpList").click(function () {
                    $(".page > .page-wrap").children().remove();
                    $(".page > .page-wrap").load("/subAll .page-subAll",function(){subAll()});
                })
            })
            //删除分站
            $("#delete-sub").click(function () {
                //获得表格CheckBox已经选中的行的信息
                var checkStatus = table.checkStatus('tab');
                //定义数组存放批量删除的行的id
                var listId = [];
                //获得所有选中行的数据
                var datas = checkStatus.data;
                //进行遍历所有选中行数据，拿出每一行的id存储到数组中
                $.each(datas, function (i,data) {
                    listId.push(data.substId);
                });
                if (listId.length <= 0) {
                    layer.msg("请选择要删除的行", {icon: 2})
                } else {
                    var confirmDel = layer.confirm('真的删除行么', function () {
                        /*window.location.replace("removeSub?substID="+checkedID);*/
                        $.ajax({
                            type: "post",
                            url: "/removeSub",
                            dataType: "json",
                            data: {"substId": listId.toString()},
                            success: function (data) {
                                $(".page > .page-wrap").children().remove();
                                $(".page > .page-wrap").load("/subAll .page-subAll",function(){subAll()});
                                layer.close(confirmDel);
                                form.render();
                            }
                        });
                    });
                }
            })
        }
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/subAll .page-subAll", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            subAll();
        });
    });

    /*分流管理  卸货入库 begin*/
    $(".list-bypass > .layui-nav-child > dd > a.nav-unload-into").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/unloadStorage .unloadStorage",function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }

            form.render();

            layui.use(['table','layer'], function () {
                var table = layui.table;
                var layer = layui.layer;

                /*left */
                table.render({
                    id:'queryTrans'
                    ,elem: '#queryTransTable'
                    , url: '/queryTrans'
                    , width: 1000
                    , height: 380
                    , cols: [[
                        {field: 'transCarloadSeqNum',  title: '装车序号'}
                        , {field: 'transNum', width:160, title: '运输单号'}
                        , {field: 'transDepartDate',  title: '发车日期'}
                        , {field: 'transStarting',  title: '出发地'}
                        , {field: 'transReachSubstation',  title: '到达分站'}
                        , {templet: '<div>{{d.truckLoading.carloadTotalNum}}</div>',  title: '总件'}
                        , {templet: '<div>{{d.truckLoading.carloadTotalWeight}}</div>',  title: '总量'}
                        , {templet: '<div>{{d.carInfo.carNumber}}</div>',  title: '车号'}
                        , {templet: '<div>{{d.carInfo.carDriverPhone}}</div>', title: '司机电话'}
                        , {templet: '<div>{{d.carInfo.carDriver}}</div>',  title: '联系人'}
                    ]]

                });/*left end */

                $("#leftTransportNumber").keydown(function(){
                    var number=$("#leftTransportNumber").val();
                    if(number!=null){
                        table.reload('queryTrans', {
                            method: "post",
                            url: "queryTrans",
                            where:{
                                carloadTransNum:number,
                            }
                        });

                    }
                });


                var trackCarloadSeqNum='';
                /*left table 行点击事件*/
                table.on('row(queryTransTable)', function(obj){
                    var data = obj.data;
                    trackCarloadSeqNum =data.transCarloadSeqNum;

                    /*right 重载*/
                    table.reload('queryWay',{
                        method:"post",
                        url:"queryWaybill",
                        where:{
                            number:data.transCarloadSeqNum,
                        }
                    });
                    /*bottom 重载*/
                    table.reload('queryBottomWay',{
                        method:"post",
                        url:"queryWaybillBottom",
                        where:{
                            number:data.transCarloadSeqNum,
                        }
                    });

                });

                /*right*/
                table.render({
                    id:'queryWay'
                    ,elem: '#queryWaybillTable'
                    , width: 1000
                    , height: 380
                    , url: 'queryWaybill'//数据接口
                    , page: true //开启分页
                    , limit: 5
                    , limits: [1, 2, 3, 5]
                    ,cellMinWidth: 80
                    , cols: [[ //表头
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'waybillConsignNum', title: '托运单号', width: 110, sort: true}
                        , {field: 'waybillConsignDate', title: '发货日期', width: 110}
                        , {field: 'waybillTransType', title: '运输类型', width: 110}
                        , {field: 'waybillReachCity', title: '到达城市', width: 110, sort: true}
                        , {templet: '<div>{{d.substation.substName}}</div>', title: '到达分站', width: 110, sort: true}
                        , {field: 'waybillTransType', title: '运输方式', width: 110, sort: true}
                        , {field: 'waybillCargoName', title: '货物名', width: 117}
                        , {field: 'waybillCargoCount', title: '数量', width: 80, sort: true}
                        , {field: 'waybillPackingWay', title: '包装', width: 80, sort: true}
                        , {field: 'waybillCargoWeight', title: '重量/KG', width: 135, sort: true}
                        , {field: 'waybillCargoVolume', title: '总体积/m³', width: 135, sort: true}
                        , {field: 'waybillRemark', title: '备注', width: 80, sort: true}
                    ]]
                });/* right end*/

                /*bottom*/
                table.render({
                    id:'queryBottomWay'
                    ,elem: '#queryWayBottomTable'
                    , width: 1750
                    , height: 380
                    , url: 'queryWaybillBottom'//数据接口
                    , page: true //开启分页
                    , limit: 5
                    , limits: [1, 2, 3, 5]
                    ,cellMinWidth: 80
                    , cols: [[ //表头
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'waybillConsignNum', title: '托运单号', width: 110, sort: true}
                        , {field: 'waybillConsignDate', title: '发货日期', width: 110}
                        , {field: 'waybillTransType', title: '运输类型', width: 110}
                        , {field: 'waybillReachCity', title: '到达城市', width: 110, sort: true}
                        , {templet: '<div>{{d.substation.substName}}</div>', title: '到达分站', width: 110, sort: true}
                        , {field: 'waybillTransType', title: '运输方式', width: 110, sort: true}
                        , {field: 'waybillCargoName', title: '货物名', width: 117}
                        , {field: 'waybillCargoCount', title: '数量', width: 80, sort: true}
                        , {field: 'waybillPackingWay', title: '包装', width: 80, sort: true}
                        , {field: 'waybillCargoWeight', title: '重量/KG', width: 135, sort: true}
                        , {field: 'waybillCargoVolume', title: '总体积/m³', width: 135, sort: true}
                        , {field: 'waybillRemark', title: '备注', width: 80, sort: true}
                    ]]
                });/* bottom end*/

                /*给卸货按钮绑定事件*/
                $("#rightWayUnload").click(function () {
                    var checkStatus = table.checkStatus('queryWay');
                    var data = checkStatus.data;

                    if (data.length==0){
                        layer.msg('请至少选中一行', {   time: 1000,   });
                    }else if (data.length>=1){
                        var ids = [];
                        //因为是json格式所以循环
                        for(var i = 0;i < data.length;i++){
                            // 将选中的行保存到数组
                            ids.push(data[i].waybillConsignNum);
                        }

                        $.ajax({
                            url:'queryWaybillBottom',
                            type:'post',
                            data:{ number:trackCarloadSeqNum,
                                num:ids.join(','),},
                            success:function(data){
                                layer.msg('入库成功', {   time: 2000,  });
                                table.reload('queryBottomWay',{
                                    method:"post",
                                    url:"queryWaybillBottom",
                                });
                                table.reload('queryWay',{
                                    method:"post",
                                    url:"queryWaybill",
                                    where:{
                                        number:trackCarloadSeqNum,
                                    }
                                });
                            }
                        });
                    }

                }); /*end*/


            });
        });
    });/*分流管理  卸货入库 end*/

    /*分流管理  分流中心 beign*/
    $(".list-bypass > .layui-nav-child > dd > a.nav-shunt-center").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/shunt .marginDiv", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }

            table.render({
                id:'tableCent'
                ,elem: '#test'
                , height: 380
                , url: 'queryShunt'//数据接口
                ,cellMinWidth: 80
                , cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'waybillConsignNum', title: '托运单号', width: 110, sort: true}
                    , {field: 'waybillConsignDate', title: '发货日期', width: 110}
                    , {field: 'waybillTransType', title: '运输类型', width: 110}
                    , {field: 'waybillReachCity', title: '到达城市', width: 110, sort: true}
                    , {templet: '<div>{{d.substation.substName}}</div>', title: '到达分站', width: 110, sort: true}
                    , {field: 'waybillTransType', title: '运输方式', width: 110, sort: true}
                    , {field: 'waybillCargoName', title: '货物名', width: 117}
                    , {field: 'waybillCargoCount', title: '数量', width: 80, sort: true}
                    , {field: 'waybillPackingWay', title: '包装', width: 80, sort: true}
                    , {field: 'waybillCargoWeight', title: '重量/KG', width: 135, sort: true}
                    , {field: 'waybillCargoVolume', title: '总体积/m³', width: 135, sort: true}
                    , {field: 'waybillRemark', title: '备注', width: 80, sort: true}
                ]]
            });/*end*/

            $("#numberShunt").keydown(function () {
                $.ajax({
                    url:'queryShunt',
                    type:'post',
                    data:{
                        number:$("#numberShunt").val(),
                    },
                    success:function(data){
                        table.reload('tableCent',{
                            method:"post",
                            url:"queryShunt",
                            where:{
                                number:$("#numberShunt").val(),
                            }
                        });
                    }
                });
            });

            $("#deliveryBtn").click(function(){
                layui.use(['table','layer'],function () {
                    var layer = layui.layer;
                    var table = layui.table;
                    var checkStatus = table.checkStatus('tableCent');
                    var data = checkStatus.data;

                    if (data.length==0){
                        layer.msg('请至少选中一行', {
                            time: 1000, //1s后自动关闭
                        });
                    }else if (data.length>=1){
                        var ids = [];
                        //因为是json格式所以循环
                        for(var i = 0;i < data.length;i++){
                            // 将选中的行保存到数组
                            ids.push(data[i].waybillConsignNum);
                        }

                        $(".page > .page-wrap").children().remove();
                        $(".page > .page-wrap").load("/delivery .delivery", function () {

                            table.render({
                                id:'deliveryTable'
                                ,elem: '#deliveryTest'
                                , height: 230
                                , url: 'queryDelivery'//数据接口
                                ,cellMinWidth: 80
                                , cols: [[ //表头
                                    {type: 'checkbox', fixed: 'left'}
                                    , {field: 'waybillConsignNum', title: '托运单号', width: 110, sort: true}
                                    , {field: 'avgMoney' , title: '分摊派送成本', default:'0',width: 110}
                                    , {field: 'waybillTransType', title: '运输类型', width: 110}
                                    , {templet: '<div>{{d.consignee.consiDetailAddress}}</div>', title: '送货地址', width: 130}
                                    , {templet: '<div>{{d.consignee.consiTelephone}}</div>', title: '联系电话', width: 130}
                                    , {field: 'waybillReachPay', title: '到付', width: 110}
                                    , {field: 'waybillCargoName', title: '货物名', width: 117}
                                    , {field: 'waybillCargoCount', title: '数量', width: 80, sort: true}
                                    , {field: 'waybillReceipt', title: '回单', width: 80, sort: true}
                                ]]

                            });/*end*/

                            table.reload('deliveryTable',{
                                method:"post",
                                url:"queryDelivery",
                                where:{
                                    number:ids.join(','),
                                },
                            });

                            $.ajax({
                                url: 'querySubs',
                                type: 'post',
                                success:function(data){
                                    $("#deliverysubs").val(data.loginSubsName);
                                    $("#deliveryName").val(data.loginName);
                                    $("#deliveryDate").val(data.nowDate);
                                    $("#deliveryId").val(data.deliveryId);
                                }
                            });

                            $.ajax({
                                type: 'post',
                                url: '/queryCarInfoAll',
                                dataType: 'json',
                                success: function (data) {
                                    //添加select第一个option
                                    $("#dataSel").append("<option selected value=''>请选择</option>");
                                    for (var i = 0; i < data.length; i++) {
                                        //添加option元素
                                        $("#dataSel").append("<option >" + data[i].carDriver + "</option>");
                                    }
                                    form.render();
                                }, error: function (data) {
                                    alert("错误");
                                }

                            });
                            $("#deliveryDrive").on('input propertychange', function() {
                                $.ajax({
                                    url: 'queryCarInfo',
                                    type: 'post',
                                    data: {
                                        name: $("#deliveryDrive").val(),
                                    },success:function(data){
                                        $("#deliveryPhone").val(data.carDriverPhone);
                                        $("#deliveryCarNumber").val(data.carNumber);
                                    }
                                });
                            });

                            form.on('submit(delivery_submit)', function (data) {
                                layui.use(['table','layer'],function () {
                                    var checkStatus = table.checkStatus('deliveryTable');
                                    var checkdata = checkStatus.data;
                                    if (checkdata.length==0){
                                        layer.msg('请至少选中一行', {
                                            time: 1000, //1s后自动关闭
                                        });
                                    } else if (checkdata.length>=1) {
                                        var ids = [];
                                        //因为是json格式所以循环
                                        for (var i = 0; i < checkdata.length; i++) {
                                            // 将选中的行保存到数组
                                            ids.push(checkdata[i].waybillConsignNum);
                                        }
                                        $.ajax({
                                            url: data.form.action,
                                            type: data.form.method,
                                            data: /*$(data.form).serialize(),*/{
                                                deliveryId:$("#deliveryId").val(),
                                                /*运单编号 数组*/
                                                number: ids.join(','),
                                                /*车牌号*/
                                                carNumber:$("#deliveryCarNumber").val(),
                                                /*派送成本*/
                                                money:$("#money").val(),
                                                /*联系电话*/
                                                phone:$("#deliveryPhone").val(),
                                            },
                                            success: function (info) {
                                                layer.msg('派送成功', {time: 2000,});
                                            }
                                        });
                                        return false;
                                    }
                                });
                            });
                        });

                    }
                })/*else end*/

            });

        });
    });/* 分流管理  分流中心   end */

    /*分流管理  派送列表 beign*/
    $(".list-bypass > .layui-nav-child > dd > a.nav-send-list").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/deliveryList .deliveryList", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText, textStatus, XMLHttpRequest);
            if (isNotAuth == false) {
                return true;
            }
            table.render({
                id:'deliveryList'
                ,elem: '#deliveryList'
                , height: 340
                , url: 'deList'//数据接口
                ,cellMinWidth: 80
                , cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'sendNum', title: '派送编号', width: 110, sort: true}
                    , {field: 'sendTime' , title: '派送日期', default:'0',width: 150}
                    , {field: 'carDriver', title: '派送司机', width: 117}
                    , {field: 'carNumber', title: '车号', width: 150, sort: true}
                    , {field: 'carDriverPhone', title: '手机号', width: 160, sort: true}
                    , {field: 'sendFee', title: '派送费用', width: 160, sort: true}
                ]]

            });/*end*/

            $("#deliverySel").click(function(){
                $("#deliveryId").val();
                table.reload('deliveryList', {
                    method: "post",
                    url: "deList",
                    where:{
                        id: $("#deliveryId").val(),
                        carName: $("#deliveryCarName").val(),
                    }
                });
            })

            $("#deliveryId").keyup(function(){
                if($("#deliveryId").val()==""){
                    table.reload('deliveryList', {
                        method: "post",
                        url: "deList",
                        where:{
                            carName: $("#deliveryCarName").val(),
                            id: $("#deliveryId").val(),
                        }
                    });
                }
            });
            $("#deliveryCarName").keyup(function(){
                if( $("#deliveryCarName").val()==""){
                    table.reload('deliveryList', {
                        method: "post",
                        url: "deList",
                        where:{
                            carName: $("#deliveryCarName").val(),
                            id: $("#deliveryId").val(),
                        }
                    });
                }
            });

            $("#deliveryBtnSel").click(function() {
                layui.use(['table', 'layer'], function () {
                    var layer = layui.layer;
                    var table = layui.table;
                    var checkStatus = table.checkStatus('deliveryList');
                    var data = checkStatus.data;
                    if (data.length == 0) {
                        layer.msg('请至少选中一行', {
                            time: 1000, //1s后自动关闭
                        });
                    } else if (data.length > 1) {
                        layer.msg('请不要选择多行', {
                            time: 1000, //1s后自动关闭
                        });
                    }else if (data.length == 1 ) {
                        var ids = [];
                        //因为是json格式所以循环
                        for (var i = 0; i < data.length; i++) {
                            // 将选中的行保存到数组
                            ids.push(data[i].sendNum);
                        }
                        $(".page > .page-wrap").children().remove();
                        $(".page > .page-wrap").load("/delivery .delivery", function () {
                            table.render({
                                id:'deliveryTable'
                                ,elem: '#deliveryTest'
                                , height: 230
                                , url: 'sendDelivery'//数据接口
                                ,cellMinWidth: 80
                                , cols: [[ //表头
                                    {type: 'checkbox', fixed: 'left'}
                                    , {field: 'waybillConsignNum', title: '托运单号', width: 110, sort: true}
                                    , {field: 'avgMoney' , title: '分摊派送成本', default:'0',width: 110}
                                    , {field: 'waybillTransType', title: '运输类型', width: 110}
                                    , {templet: '<div>{{d.consignee.consiDetailAddress}}</div>', title: '送货地址', width: 130}
                                    , {templet: '<div>{{d.consignee.consiTelephone}}</div>', title: '联系电话', width: 130}
                                    , {field: 'waybillReachPay', title: '到付', width: 110}
                                    , {field: 'waybillCargoName', title: '货物名', width: 117}
                                    , {field: 'waybillCargoCount', title: '数量', width: 80, sort: true}
                                    , {field: 'waybillReceipt', title: '回单', width: 80, sort: true}
                                ]],done: function(res, page, count) {

                                    //可以自行添加判断的条件是否选中
                                    //这句才是真正选中，通过设置关键字LAY_CHECKED为true选中，这里只对第一行选中
                                    for (var i = 0; i < res.data.length; i++) {
                                        res.data[i]["LAY_CHECKED"] = 'true';
                                        //下面三句是通过更改css来实现选中的效果
                                        var index = res.data[i]['LAY_TABLE_INDEX'];
                                        $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                                        $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked')
                                    }
                                }

                            });/*end*/

                            table.reload('deliveryTable',{
                                method:"post",
                                url:"sendDelivery",
                                where:{
                                    sendNum:ids.join(','),
                                },
                            });

                            $.ajax({
                                url: 'sendDeliveryTips',
                                type: 'post',
                                data: { sendNum:ids.join(','),},
                                success:function(data){
                                    $("#deliverysubs").val(data.loginSubsName);
                                    $("#deliveryName").val(data.loginName);
                                    $("#deliveryDate").val(data.bean.sendTime);
                                    $("#deliveryId").val(data.bean.sendNum);
                                    $("#money").val(data.bean.sendFee);
                                    $("#deliveryDrive").val(data.bean.carDriver);
                                    $("#deliveryPhone").val(data.bean.carDriverPhone);
                                    $("#deliveryCarNumber").val(data.bean.carNumber);

                                }
                            });

                            $.ajax({
                                type: 'post',
                                url: '/queryCarInfoAll',
                                dataType: 'json',
                                success: function (data) {
                                    //添加select第一个option
                                    $("#dataSel").append("<option selected value=''>请选择</option>");
                                    for (var i = 0; i < data.length; i++) {
                                        //添加option元素
                                        $("#dataSel").append("<option >" + data[i].carDriver + "</option>");
                                    }
                                    form.render();
                                }, error: function (data) {
                                    alert("错误");
                                }

                            });
                            $("#deliveryDrive").on('input propertychange', function() {
                                $.ajax({
                                    url: 'queryCarInfo',
                                    type: 'post',
                                    data: {
                                        name: $("#deliveryDrive").val(),
                                    },success:function(data){
                                        $("#deliveryPhone").val(data.carDriverPhone);
                                        $("#deliveryCarNumber").val(data.carNumber);
                                    }
                                });
                            });


                            form.on('submit(delivery_submit)', function (data) {
                                layui.use(['table','layer'],function () {
                                    var checkStatus = table.checkStatus('deliveryTable');
                                    var checkdata = checkStatus.data;
                                    if (checkdata.length==0){
                                        layer.msg('请至少选中一行', {
                                            time: 1000, //1s后自动关闭
                                        });
                                    } else if (checkdata.length>=1) {
                                        var idss = [];
                                        //因为是json格式所以循环
                                        for (var i = 0; i < checkdata.length; i++) {
                                            // 将选中的行保存到数组
                                            idss.push(checkdata[i].waybillConsignNum);
                                        }
                                        $.ajax({
                                            url: 'updateDelivery',
                                            type: data.form.method,
                                            data: {
                                                deliveryId:$("#deliveryId").val(),
                                                /* /!*运单编号 数组*!/*/
                                                number: idss.join(','),
                                                /*/!*车牌号*!/*/
                                                carNumber:$("#deliveryCarNumber").val(),
                                                /*/!*派送成本*!/*/
                                                money:$("#money").val(),
                                            },
                                            success: function (info) {
                                                layer.msg('派送修改成功', {time: 2000,});
                                            }
                                        });
                                        return false;
                                    }
                                });
                            });

                        });/*派送清单页面  end*/
                    }

                });
            });

        });
    });/* 派送列表 end --*/

    /*资料修改 系统管理*/
    $(".list-sys > .layui-nav-child > dd > a.nav-sys-info").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/dataUpdate .common-body", function () {

            form.render();
            bindingSelect();
            $("#province").on("change", function () {
                chooseProvince($(this).get(0))
            });
            $("#city").on("change", function () {
                chooseCity($(this).get(0));
            });


            $(function () {
                $.ajax({
                    type:"post",
                    url: "/company/query",
                    dataType: "json",
                    data: {"comUserAccount": "yiersan"},
                    success: function (data) {
                        $("#comUserAccount").val(data.comUserAccount);
                        $("#password").val(data.comUserName);
                        $("#comType").val(data.comType);
                        $("#companyname").val(data.comName);
                        $("#coltd").val(data.comShortName);
                        $("#HomePages").val(data.comUrl);
                        $("#citySub").val(data.comMasterStation);
                        $("#sheng").val(data.comAddress);
                        $("#comDetailAddress").val(data.comDetailAddress);
                        $("#comLinkman").val(data.comLinkman);
                        $("#comContactPhone").val(data.comContactPhone);
                        $("#comTelephone").val(data.comTelephone);
                        $("#comEmail").val(data.comEmail);
                        /*短信发送 复选框*/
                        $("#EmployeeNum").val(data.comEmp);
                        /*运单生成 单选框*/
                        /*logo图片*/

                        console.log(data);
                    }
                });
            });

            form.render();

            /*判断密码是否一致*/
            $("#password1").keyup(function () {
                if ($("#password1").val().length==0){
                    $("#checkPassword").html("");
                } else if ($("#password").val() != $("#password1").val()){
                    $("#checkPassword").html("请保证两次输入密码的一致性！")
                    return false;
                } else {
                    $("#checkPassword").html("密码一致");
                }
            }); /*end*/

            /*判断密码长度*/
            $("#password").keyup(function () {
                if ($("#password").val().length<6){
                    $("#checkPassLenght").html("长度必须大于6个字符");
                }else{
                    $("#checkPassLenght").html("");
                }
            });/*end*/

            $("#updateSubmit").click(function () {
                layui.use(['table','layer'],function () {
                    $.ajax({
                        type: "post",
                        url: "/company/update",
                        data: $("#userinfoForm").serializeArray(),
                        success: function (data) {
                            layer.msg('修改成功', {time: 2000,});
                            console.log(data);
                        }
                    });
                });
            });

        });
    });

    /*跟踪管理*/
    /*新增跟踪*/
    $(".list-track > .layui-nav-child > dd > a.nav-add-track").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/goAddTrack .page-this", function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }

            laydate.render({ //承诺日期
                elem: '#waybillConsignDate', //指定元素
                theme: "#5974d9"
            });
            laydate.render({ //承诺日期
                elem: '#waybillPromiseDate', //指定元素
                theme: "#5974d9"
            });

            //搜索跟踪记录监听提交
            form.on('submit(trackSearch)', function(data){
                console.log(data.field);

                data.field['page'] = 1;
                data.field['count'] = 10;


                table.reload('track-info', {
                    method: "post"
                    , url: "/queryTrackByCondition"
                    , where: {trackWaybillCondition: JSON.stringify(data.field)}
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });

                return false;
            });
            form.render();

            //查询所有跟踪
            $(".track-list-btn-group .allTrack").click(function(){
                table.reload('track-info', {
                    method: "post"
                    , url: "/queryTrackLimitLayui"
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });
            //查询未签收运单的跟踪记录
            $(".track-list-btn-group .search-noSign").click(function(){
                table.reload('track-info', {
                    method: "post"
                    , url: "/queryTrackNoSign"
                    , where: {
                        page: 1,
                        limit: 10
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });
            //新增跟踪页面
            $(".track-list-btn-group .addTrack-btn").click(function () {
                layer.open({
                    title: '<i class="layui-icon">&#xe654;</i>新增跟踪记录',
                    type: 2,
                    skin: 'layui-layer-lan',
                    area: ['650px', '440px'], //宽高
                    content: '/static/pages/addTrackLayer.html',
                    end:function () {
                        table.reload("track-info");
                    }
                });
            });
            //运单跟踪信息表格渲染
            var trackTable = table.render({
                elem: '#track-info'
                ,id: 'track-info'
                ,height: 480
                ,url: '/queryTrackLimitLayui' //数据接口
                ,page: true //开启分页
                ,cols: [[ //表头
                    {type: 'numbers', width:50, title: '#'}
                    ,{field: 'trackConsignNum', width:200, title: '托运单号'}
                    ,{field: 'trackDate', width:200, title: '跟踪日期', sort: true}
                    ,{field: 'trackStatus', width:300, title: '跟踪状态'}
                    ,{title: '跟踪类型',  width: 100,
                        templet:function (d) {
                            var trackType = d.trackType;
                            var content = "";
                            switch (trackType) {
                                case 1:
                                    content = "收件";
                                    break;
                                case 2:
                                    content = "准备装车";
                                    break;
                                case 3:
                                    content = "装车";
                                    break;
                                case 4:
                                    content = "运输";
                                    break;
                                case 5:
                                    content = "转运";
                                    break;
                                case 6:
                                    content = "派送";
                                    break;
                                case 7:
                                    content = "签收";
                            }

                            return content;
                        }
                    }
                    ,{title: '操作', width:178, align:'center', toolbar: '#operation-bar'}
                    ,{field: 'empName', width:100, title: '录入员'}
                    ,{field: 'waybillConsignDate', width:150, title: '托运日期', sort: true}
                    ,{field: 'waybillReachCity', width:100, title: '到达城市'}
                    ,{field: 'waybillCargoName', width:200, title: '货物名称'}
                    ,{field: 'waybillCargoCount', width:100, title: '数量', sort: true}
                    ,{field: 'shipperCom', width:200, title: '发货单位'}
                    ,{field: 'consiCom',width:200, title: '收货单位'}
                ]]
            });
            //监听工具条
            table.on('tool(track-info)', function(obj){
                var data = obj.data;
                if(obj.event === 'del'){
                    console.log(obj);
                    layer.confirm('真的要删除记录么?',{title: "<i class='layui-icon'>&#xe702;</i>提示",}, function(index){
                        obj.del();
                        layer.close(index);
                        $.ajax({
                            url:"/deleteTrack",
                            data:{trackId: data.trackId},
                            dataType: "json",
                            success:function (msg) {
                                console.log(msg);
                                layer.msg(msg['msg'], {icon: 6, time: 1400});
                                if (data['result'] == "success") {

                                } else {

                                }
                            }
                        });
                    });
                } else if(obj.event === 'edit'){
                    window.sessionStorage.setItem("trackId",data.trackId);
                    layer.open({
                        title: '<i class="layui-icon">&#xe654;</i>新增跟踪记录',
                        type: 2,
                        skin: 'layui-layer-lan',
                        area: ['650px', '440px'], //宽高
                        content: '/static/pages/updateTrackLayer.html',
                        end:function () {
                            table.reload("track-info");
                        }
                    });
                }
            });

        });
    });


    // 财务结算 收入明细
    $(".list-finance > .layui-nav-child > dd > a.nav-income").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/income .page-income",function (responseText,textStatus,XMLHttpRequest) {
            var isNotAuth = noAuth(responseText,textStatus,XMLHttpRequest);
            if (isNotAuth == false){
                return true;
            }
            //新增收入
            $("#insertIncome").click(function () {

                layer.open({
                    type: 1
                    ,title: ['新增收入💴', 'font-size:18px;background-color: #38b4ee;']
                    ,closeBtn: 1
                    ,area: '900px;'
                    ,shade: 0.8
                    ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                    ,btnAlign: 'c'
                    ,moveType: 1 //拖拽模式，0或者1
                    ,content: '<form class="layui-form" action="" lay-filter="example">' +
                        '<div class="insertIncome-from">\n' +
                        '      <div class="input-group">\n' +
                        '        <table class="insertIncome-table"  >\n' +
                        '            <tr style="text-align: center">\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon1">录入日期</span>\n' +
                        '                    <input type="date" name="incomeEnteringDate" class="form-control" id="insertIncomeTime" aria-describedby="basic-addon1">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon2">操作站点</span>\n' +
                        '                    <input type="text" name="incomeSubstId" id="incomeSubstId" readonly="readonly" class="form-control" aria-describedby="basic-addon1">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon3">所属部门</span>\n' +
                        '                    <input type="text" name="incomeDepartment" value="哈哈" readonly="readonly" class="form-control"  aria-describedby="basic-addon1">\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon4">收入科目</span>\n' +
                        '                    <select class="form-control" id="exampleFormControlSelect1" name="incomeCourse">\n' +
                        '                        <option value="" selected="selected">请选择</option>\n' +
                        '                        <option value=\'营业收入\'>营业收入</option>                                                                                                  ";\n' +
                        '                        <option value=\'营业外收入\'>营业外收入</option>                                                                                                  ";                                                                                      ";\n' +
                        '                        <option value=\'运营开支\'>运营开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'行政开支\'>行政开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'办公开支\'>办公开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'出差开支\'>出差开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'人员工资\'>人员工资</option>                                                                                                  ";\n' +
                        '                        <option value=\'运输开支\'>运输开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'派送开支\'>派送开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'外包开支\'>外包开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'提货开支\'>提货开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'其他开支\'>其他开支</option>\n' +
                        '                    </select>\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon5">收入金额</span>\n' +
                        '                    <input type="text" class="form-control" name="incomeCredit" aria-describedby="basic-addon1">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon6">收入方式</span>\n' +
                        '                    <select class="form-control" id="exampleFormControlSelect2" name="incomeWay">\n' +
                        '                        <option value="" selected="selected">请选择</option>\n' +
                        '                        <option value="现金支付">现金支付</option>\n' +
                        '                        <option value="公司转账">公司转账</option>\n' +
                        '                        <option value="微信">微信</option>\n' +
                        '                        <option value="支付宝">支付宝</option>\n' +
                        '                    </select>\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon7">收入内容</span>\n' +
                        '                    <input type="text" class="form-control"  aria-describedby="basic-addon1" name="incomeContent">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon8">凭证号</span>\n' +
                        '                    <input type="text" class="form-control" aria-describedby="basic-addon1" name="incomeVoucherNum">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon9">付款对象</span>\n' +
                        '                    <input type="text" class="form-control"  aria-describedby="basic-addon1" name="incomePayObj">\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon11">收支类型</span>\n' +
                        '                    <select class="form-control" id="exampleFormControlSelect3" name="incomeType">\n' +
                        '                        <option value="" selected="selected">请选择</option>\n' +
                        '                        <option value="出港费用">出港费用</option>\n' +
                        '                        <option value="进港费用">进港费用</option>\n' +
                        '                    </select>\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon12">进港站点</span>\n' +
                        '                    <input type="text" class="form-control" aria-describedby="basic-addon1" name="incomeArrivalStation">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon13">录入员</span>\n' +
                        '                    <input type="text" readonly="readonly" class="form-control"  aria-describedby="basic-addon1" name="incomeTypeinPerson">\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td style="border: 0px solid #d9edf7;">\n' +
                        '                    <i class="table-i">备注：</i>\n' +
                        '                    <textarea class="table-textarea" placeholder="请输入内容" style="width:200px;height: 50px" name="incomeRemark"></textarea>\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td style="border: 0px solid #d9edf7;">\n' +
                        '                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="insertIncome" style="background-color: #1E9FFF">确定</button>\n' +
                        '                    <button type="button" class="layui-btn layui-btn-primary">取消</button>\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '        </table>\n' +
                        '    </div>' +
                        '</div>' +
                        '</from>'
                    ,success: function(){
                        $.ajax({
                            type: "POST",
                            url: "/getLoginedEmp",
                            success: function (data) {
                                $("input[name='incomeSubstId']").val(data['empSubstId']);
                                $("input[name='incomeDepartment']").val(data['empDepartment']);
                                $("input[name='incomeTypeinPerson']").val(data['empName']);//录入员
                            }
                        });
                        //获取系统当前时间
                        $(document).ready(function () {
                            var time = new Date();
                            var day = ("0" + time.getDate()).slice(-2);
                            var month = ("0" + (time.getMonth() + 1)).slice(-2);
                            var today = time.getFullYear() + "-" + (month) + "-" + (day);
                            $('#insertIncomeTime').val(today);
                        })
                        form.on('submit(insertIncome)', function(data){
                            $.ajax({
                                contentType: "application/json;charset=UTF-8",
                                type: "post",
                                url: "/addIncome",
                                dataType: "json",
                                data: JSON.stringify(data.field),
                                success: function (data) {
                                    //新增收支明细
                                    $.ajax({
                                        contentType: "application/json;charset=UTF-8",
                                        type: "post",
                                        url: "/addIncome",
                                        dataType: "json",
                                        data: JSON.stringify(data.field),
                                        success: function (data) {
                                        }
                                    })
                                    layer.msg(data['msg'], {icon: 6, time: 1400});
                                    parent.layer.close(1);
                                    table.reload('selectAllIncome', {
                                        page: {
                                            curr: 1
                                        }
                                    });
                                }
                            })
                            return false;
                        });
                    }
                });

            })

            laydate.render({
                elem: '#begin'
                ,theme: 'grid'
            });
            laydate.render({
                elem: '#end'
                ,theme: 'grid'
            });
            layui.use('table', function(){
                var table = layui.table;
                table.render({
                    elem: '#selectAllIncome'
                    ,url:'/selectAllIncome'
                    , width: 1660
                    , height: 380
                    , id:'selectAllIncome'
                    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                        layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                        //,curr: 5 //设定初始在第 5 页
                        ,groups: 1 //只显示 1 个连续页码
                        ,first: false //不显示首页
                        ,last: false //不显示尾页
                    }
                    ,cols: [[
                        {type:'numbers',title:"序号"}
                        ,{templet:'<div>{{d.finance.inspendFound}}</div>', title:'资金项目',width:90}//  收支明细表
                        ,{field:'incomeCredit', title:'收入金额',width:90}
                        ,{field:'incomeCourse', title:'收支科目' ,width:105}
                        ,{field:'incomeType', title: '收支类型',width:90}
                        ,{field:'incomeWay', title:'收支方式',width:90}
                        ,{field:'incomeArrivalStation', title:'进港站点',width:90}
                        ,{field:'incomeSubstId', title:'发生站点',width:90}//
                        ,{field:'incomeContent', title:'收支内容',width:110}
                        ,{field:'incomeTypeinPerson', title:'操作员',width:90}
                        ,{field:'incomePayObj', title:'付款对象',width:90}
                        ,{field:'incomeRemark', title:'备注',width:150}
                        ,{templet:'<div>{{d.finance.inspendPersonCheck}}</div>', title:'个人审核',width:90}// //  收支明细表inspendPersonCheck
                        ,{templet:'<div>{{d.finance.inspendVerifier}}</div>', title:'审核人',width:90}////  收支明细表inspendVerifier
                        ,{templet:'<div>{{d.finance.inspendSubstationCheck}}</div>', title:'分站审核',width:90}////  收支明细表inspendSubstationCheck
                        ,{templet:'<div>{{d.finance.inspendSubstationVerifier}}</div>',title:'分站审核人',width:110}////  收支明细表inspendSubstationVerifier
                        ,{field:'incomeVoucherNum', title:'凭证号',width:120}
                    ]]

                });
            });
        })
    });

    // 财务结算 开支明细
    $(".list-finance > .layui-nav-child > dd > a.nav-spend").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/spend .page-income",function () {
            $.ajax({
                type: "POST",
                url: "/getSubstationListFS",
                success: function(data){
                    for (var i = 0; i < data.length; i++) {
                        var li = "<option value='"+data[i]['substName']+"'>"+data[i]['substName']+"</option>"
                        $("select[name='financeOccurStation']").append(li);
                    }
                }
            });
            //新增开支
            $("#insertIncome").click(function () {

                var SpendOpen = layer.open({
                    type: 1
                    ,title: ['新增开支💴', 'font-size:18px;background-color: #38b4ee;']
                    ,closeBtn: 1
                    ,area: '900px;'
                    ,shade: 0.8
                    ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                    ,btnAlign: 'c'
                    ,moveType: 1 //拖拽模式，0或者1
                    ,content: '<form class="layui-form" action="" lay-filter="example">' +
                        '<div class="insertIncome-from">\n' +
                        '      <div class="input-group">\n' +
                        '        <table class="insertIncome-table"  >\n' +
                        '            <tr style="text-align: center">\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon1">录入日期</span>\n' +
                        '                    <input type="date" name="spendEnteringDate" class="form-control" id="insertIncomeTime" aria-describedby="basic-addon1">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon2">操作站点</span>\n' +
                        '                    <input type="text" name="spendSubstId" id="spendSubstId" readonly="readonly" class="form-control" aria-describedby="basic-addon1">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon3">所属部门</span>\n' +
                        '                    <input type="text" name="spendDepartment" readonly="readonly" class="form-control"  aria-describedby="basic-addon1">\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon4">开支科目</span>\n' +
                        '                    <select class="form-control" id="exampleFormControlSelect1" name="spendCourse">\n' +
                        '                        <option value="" selected="selected">请选择</option>\n' +
                        '                                                                                                                         ";                                                                                      ";\n' +
                        '                        <option value=\'运营开支\'>运营开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'行政开支\'>行政开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'办公开支\'>办公开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'出差开支\'>出差开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'人员工资\'>人员工资</option>                                                                                                  ";\n' +
                        '                        <option value=\'运输开支\'>运输开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'派送开支\'>派送开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'外包开支\'>外包开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'提货开支\'>提货开支</option>                                                                                                  ";\n' +
                        '                        <option value=\'其他开支\'>其他开支</option>\n' +
                        '                    </select>\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon5">支出金额</span>\n' +
                        '                    <input type="text" class="form-control" name="spendDebit" aria-describedby="basic-addon1">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon6">开支方式</span>\n' +
                        '                    <select class="form-control" id="exampleFormControlSelect2" name="spendWay">\n' +
                        '                        <option value="" selected="selected">请选择</option>\n' +
                        '                        <option value="现金支付">现金支付</option>\n' +
                        '                        <option value="公司转账">公司转账</option>\n' +
                        '                        <option value="微信">微信</option>\n' +
                        '                        <option value="支付宝">支付宝</option>\n' +
                        '                    </select>\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon7">开支内容</span>\n' +
                        '                    <input type="text" class="form-control"  aria-describedby="basic-addon1" name="spendContent">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon8">凭证号</span>\n' +
                        '                    <input type="text" class="form-control" aria-describedby="basic-addon1" name="spendVoucherNum">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon9">付款对象</span>\n' +
                        '                    <input type="text" class="form-control"  aria-describedby="basic-addon1" name="spendPayObj">\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon11">开支类型</span>\n' +
                        '                    <select class="form-control" id="exampleFormControlSelect3" name="spendType">\n' +
                        '                        <option value="" selected="selected">请选择</option>\n' +
                        '                        <option value="出港费用">出港费用</option>\n' +
                        '                        <option value="进港费用">进港费用</option>\n' +
                        '                    </select>\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon"' +
                        'id="basic-addon12">进港站点</span>\n' +
                        '                    <input type="text" class="form-control" aria-describedby="basic-addon1" name="spendArrivalStation">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <span class="input-group-addon" id="basic-addon13">录入员</span>\n' +
                        '                    <input type="text" readonly="readonly" class="form-control"  aria-describedby="basic-addon1" name="spendTypeinPerson">\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td style="border: 0px solid #d9edf7;">\n' +
                        '                    <i class="table-i">备注：</i>\n' +
                        '                    <textarea class="table-textarea" placeholder="请输入内容" style="width:200px;height: 50px" name="spendRemark"></textarea>\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '            <tr>\n' +
                        '                <td style="border: 0px solid #d9edf7;">\n' +
                        '                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="insertSpend" style="background-color: #1E9FFF">确定</button>\n' +
                        '                    <button type="button" class="layui-btn layui-btn-primary">取消</button>\n' +
                        '                </td>\n' +
                        '            </tr>\n' +
                        '        </table>\n' +
                        '    </div>' +
                        '</div>' +
                        '</from>'
                    ,success: function(){
                        $.ajax({
                            type: "POST",
                            url: "/getLoginedEmp",
                            success: function (data) {
                                $.ajax({
                                    type: "POST",
                                    url: "/selectSubNameById",
                                    data:{empSubstId:data.empSubstId},
                                    dataType:"text",
                                    success: function (data) {
                                        $("input[name='spendSubstId']").val(data);
                                    }
                                });
                                $("input[name='spendDepartment']").val(data['empDepartment']);
                                $("input[name='spendTypeinPerson']").val(data['empName']);//录入员
                            }
                        });
                        //获取系统当前时间
                        $(document).ready(function () {
                            var time = new Date();
                            var day = ("0" + time.getDate()).slice(-2);
                            var month = ("0" + (time.getMonth() + 1)).slice(-2);
                            var today = time.getFullYear() + "-" + (month) + "-" + (day);
                            $('#insertIncomeTime').val(today);
                        })
                        form.on('submit(insertSpend)', function(data){
                            $.ajax({
                                contentType: "application/json;charset=UTF-8",
                                type: "post",
                                url: "/addSpend",
                                dataType: "json",
                                data: JSON.stringify(data.field),
                                success: function (data) {
                                    layer.msg(data['msg'], {icon: 6, time: 1400});
                                    parent.layer.close(SpendOpen)
                                    table.reload('selectAllSpend', {
                                        page: {
                                            curr: 1
                                        }
                                    });
                                }
                            })
                            return false;
                        });
                    }
                });

            })

            laydate.render({
                elem: '#begin'
                ,theme: 'grid'
            });
            laydate.render({
                elem: '#end'
                ,theme: 'grid'
            });
            layui.use('table', function(){
                //根据条件查询
                form.on('submit(selectSpendByCondition)', function(data){
                    data.field['page'] = spendTable['config']['page']['curr'];
                    data.field['count'] = spendTable['config']['page']['count'];
                    data.field['limit'] = spendTable['config']['page']['limit'];
                    table.reload('selectAllSpend', {
                        method: "post"
                        , url: "/selectSpendByCondition"
                        , where: {
                            financeCondition: JSON.stringify(data.field)
                        }
                        , page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });

                    return false;
                });
                var table = layui.table;
                var spendTable = table.render({
                    elem: '#selectAllSpend'
                    ,url:'/selectAllSpend'
                    , width: 1760
                    , height: 380
                    , id:'selectAllSpend'
                    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                        //,curr: 5 //设定初始在第 5 页
                        groups: 1 //只显示 1 个连续页码
                        ,first: false //不显示首页
                        ,last: false //不显示尾页
                    }
                    ,cols: [[
                        {type:'numbers',title:"序号"}
                        ,{templet:'<div>{{d.finance.inspendFound}}</div>', title:'资金项目',width:90}//  收支明细表
                        ,{field:'spendEnteringDate', title:'开支日期',width:110}
                        ,{field:'spendDebit', title:'支出金额',width:90}
                        ,{field:'spendCourse', title:'开支科目' ,width:105}
                        ,{field:'spendType', title: '开支类型',width:90}
                        ,{field:'spendWay', title:'开支方式',width:90}
                        ,{field:'spendArrivalStation', title:'进港站点',width:90}
                        ,{field:'spendSubstId', title:'发生站点',width:90}//
                        ,{field:'spendContent', title:'开支内容',width:110}
                        ,{field:'spendTypeinPerson', title:'操作员',width:90}
                        ,{field:'spendPayObj', title:'付款对象',width:90}
                        ,{field:'spendRemark', title:'备注',width:150}
                        ,{templet:'<div>{{d.finance.inspendPersonCheck}}</div>', title:'个人审核',width:90}// //  收支明细表inspendPersonCheck
                        ,{templet:'<div>{{d.finance.inspendVerifier}}</div>', title:'审核人',width:90}////  收支明细表inspendVerifier
                        ,{templet:'<div>{{d.finance.inspendSubstationCheck}}</div>', title:'分站审核',width:90}////  收支明细表inspendSubstationCheck
                        ,{templet:'<div>{{d.finance.inspendSubstationVerifier}}</div>',title:'分站审核人',width:110}////  收支明细表inspendSubstationVerifier
                        ,{field:'spendVoucherNum', title:'凭证号',width:120}
                    ]]

                });
            });
        })
    })
    // 财务结算 收支明细
    $(".list-finance > .layui-nav-child > dd > a.nav-inspend").click(function () {
        $(".page > .page-wrap").children().remove();
        $(".page > .page-wrap").load("/finance .page-income",function () {
            //个人审核
            $("#updatePersonal").click(function (){
                var table = layui.table;
                var updatePersonal=table.checkStatus("selectAllFinance");
                var ids=[]
                $(updatePersonal.data).each(function (i, o) {//o即为表格中一行的数据
                    ids.push(o.inspendId);
                });
                $.ajax({
                    url:"/updatePersonal"
                    ,type:"POST"
                    ,data:{ids:ids}
                    ,traditional:true
                    ,success:function () {
                        table.render({
                            page:1
                        });
                        layer.msg("审核成功", {icon: 6, time: 1400});
                    }
                })
            })
            //分站审核
            $("#updateSubstation").click(function (){
                var table = layui.table;
                var updateSubstation=table.checkStatus("selectAllFinance");
                var ids=[]
                $(updateSubstation.data).each(function (i, o) {//o即为表格中一行的数据
                    ids.push(o.inspendId);
                });
                $.ajax({
                    url:"/updateSubstation"
                    ,type:"POST"
                    ,data:{ids:ids}
                    ,traditional:true
                    ,success:function () {
                        table.reload('FinanceTbale', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                        layer.msg("审核成功", {icon: 6, time: 1400});
                    }
                })
            })
            $.ajax({
                type: "POST",
                url: "/getSubstationListFS",
                success: function(data){
                    for (var i = 0; i < data.length; i++) {
                        var li = "<option value='"+data[i]['substName']+"'>"+data[i]['substName']+"</option>"
                        $("select[name='financeOccurStation']").append(li);
                    }
                }

            })
            laydate.render({
                elem: '#begin'
                ,theme: 'grid'
            });
            laydate.render({
                elem: '#end'
                ,theme: 'grid'
            });
            layui.use('table', function(){
                //根据条件查询
                form.on('submit(selectFinanceByCondition)', function(data){
                    data.field['page'] = FinanceTbale['config']['page']['curr'];
                    data.field['count'] = FinanceTbale['config']['page']['count'];
                    data.field['limit'] = FinanceTbale['config']['page']['limit'];
                    table.reload('selectAllFinance', {
                        method: "post"
                        , url: "/selectFinanceByCondition"
                        , where: {
                            financeCondition: JSON.stringify(data.field)
                        }
                        , page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });

                    return false;
                });
                var table = layui.table;

                var FinanceTbale = table.render({

                    elem: '#selectAllFinance'
                    ,url:'/selectAllFinance'
                    , width: 1916
                    , height: 380
                    , id:'selectAllFinance'
                    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                        //,curr: 5 //设定初始在第 5 页
                        groups: 1 //只显示 1 个连续页码
                        ,first: false //不显示首页
                        ,last: false //不显示尾页
                    }
                    ,totalRow: true //开启合计行
                    ,cols: [[
                        {type:'numbers',title:"序号" , edit: 'text'}
                        ,{type: 'checkbox'}
                        ,{field:'inspendFound',height:20, title:'资金项目', width:90,totalRowText: '合计'}
                        ,{field:'inspendId', title:'id',width:110, hide:true}
                        ,{field:'inspendDate', title:'开支日期',width:110}
                        ,{field:'inspendSpendmoney', title:'支出金额',width:90, totalRow: true}
                        ,{field:'inspendIncomemoney', title:'收入金额',width:90, totalRow: true}
                        ,{field:'inspendCourse', title:'开支科目' ,width:105}
                        ,{field:'inspendType', title: '开支类型',width:90}
                        ,{field:'inspendWay', title:'开支方式',width:90}
                        ,{field:'inspendArrivalStation', title:'进港站点',width:90}
                        ,{field:'inspendOccurStation', title:'发生站点',width:90}//
                        ,{field:'inspendContent', title:'开支内容',width:110}
                        ,{field:'inspendOperator', title:'操作员',width:90}
                        ,{field:'inspendPayObj', title:'付款对象',width:90}
                        ,{field:'inspendRemark', title:'备注',width:150}
                        ,{field:'inspendPersonCheck', title:'个人审核',width:90}// //  收支明细表inspendPersonCheck
                        ,{field:'inspendVerifier', title:'审核人',width:90}////  收支明细表inspendVerifier
                        ,{field:'inspendSubstationCheck', title:'分站审核',width:90}////  收支明细表inspendSubstationCheck
                        ,{field:'inspendSubstationVerifier',title:'分站审核人',width:110}////  收支明细表inspendSubstationVerifier
                        ,{field:'inspendVoucherNum', title:'凭证号',width:120}

                    ]]

                });
            });
        })
    })

    //登出当前账号
    $(".list-sys > .layui-nav-child > dd > a.nav-exit").click(function () {
        layer.open({
            type: 0,
            title: "温馨提示",
            content: "您确定要退出系统吗？",
            btn: ['确定','取消'],
            yes:function(){

                //根据托运单号删除对应运单信息
                $.ajax({
                    url: "/logout",
                    type: "POST",
                    dataType: "json",
                    data: {},
                    success: function (data) {
                        console.log(data);
                        layer.msg(data['msg']);
                        window.location.href = "/";
                    }
                });
            }
        });
    });


    /**
     * 跳转页面无权限提示
     * @param responseText
     * @param textStatus
     */
    function noAuth(responseText,textStatus,XMLHttpRequest) {
        var isNotAuth = true;
        if (textStatus == "error"){
            layer.open({
                title: '提示',
                type: 1,
                closeBtn: 0,
                btn:['知道了'],
                skin: 'layui-layer-lan',
                area:['300px','150px'],
                content: responseText,
                end:function(){
                    layer.load(1, {
                        shade: [0.3, '#fff'], //0.1透明度的白色背景
                        time: 1000,
                        end:function () {
                            window.location.href = "/";
                        }
                    });
                }
            });
            isNotAuth = false;
        }

        return isNotAuth;
    }

    //新增运单页面对象
    let addWaybill = {
        billing:"",
        payment:"",
        initPage:function (billing,payment) {
            if (typeof(billing) != "undefined"){
                this.billing = billing;
            } else {
                $("input[name='waybillConsignNum']").val(generateWaybillConsignNum());
                $("button.flush-waybillConsignNum").click(function () {
                    $("input[name='waybillConsignNum']").val(generateWaybillConsignNum());
                });
            }
            if (typeof(payment) != "undefined"){
                this.payment = payment;
            }

            //刷新表单到达站、出发站的下拉列表
            loadSubstList(["waybillStartingSubst", "waybillReachSubst"]);
            //加载发货方下拉列表和发货方下拉列表
            loadShipperList();
            loadConsiList();

            //加载开单员，即当前登录用户
            loadNowLoginEmpInfo();

            //绑定日期选择框
            loadLayDate({elem:'#shipping-date',isNow:true });
            loadLayDate({elem:'#promise-date',isNow:false });


        },
        bindEvent:function () {

            //绑定新增发货方点击事件
            $('.add-shipper').click(function () {
                window.sessionStorage.setItem("event","add");

                var index = layer.open({
                    type:2,//设置类型 默认0 1页面层 2弹出层
                    title:'新增发货方资料',
                    skin:'layui-layer-molv',//皮肤
                    content: 'static/pages/shipperLayer.html', //支持传入html
                    //大小
                    area:['1050px', '400px'],//'auto',
                    btnAlign :'c', //按钮对齐方式
                    closeBtn: 1, //关闭按钮样式默认1
                    shade:[0.8,'#393d49'],//遮罩：第一个参数透明度第二个参数颜色
                    shadeClose:true,//点击遮罩是否关闭弹出层默认是false
                    anim:1, //设置关闭动画
                    end:function () {
                        loadShipperList();
                    }
                });
            });
            //绑定新增收货方点击事件
            $('.add-consi').click(function () {
                window.sessionStorage.setItem("event","add");

                var index = layer.open({
                    type:2,//设置类型 默认0 1页面层 2弹出层
                    title:'添加收货方资料',
                    skin:'layui-layer-molv',//皮肤
                    content: 'static/pages/consiLayer.html', //支持传入html
                    //大小
                    area:['1050px', '400px'],//'auto',
                    btnAlign :'c', //按钮对齐方式
                    closeBtn: 1, //关闭按钮样式默认1
                    shade:[0.8,'#393d49'],//遮罩：第一个参数透明度第二个参数颜色
                    shadeClose:true,//点击遮罩是否关闭弹出层默认是false
                    anim:1, //设置关闭动画
                    end:function () {
                        loadConsiList();
                    }
                });
            });

            //加载出发分站的司机
            form.on('select(waybillStartingSubst)', function(data){
                loadCarDriverList(data.value);
            });

            /********计费方式选择*********/
            form.on('select(waybillChargeMode)', function(data){
                console.log(data.value);//得到被选中的值

                addWaybill.billing = data.value;
                //基本运费值改变
                addWaybill.basicFreightCalc(data.value);
            });

            //付费方式选择
            form.on('select(waybillPaymentMethod)', function(data){
                console.log(data.value);//得到被选中的值
                addWaybill.payment = data.value;
                //付费方式改变
                addWaybill.paymentChange(addWaybill.payment);
            });

            //计费因数值改变，重新求基本运费
            $("input[name='waybillCargoCount'],input[name='waybillCargoWeight'],input[name='waybillCargoVolume'],input[name='waybillCargoPrice']").on("change",function () {
                addWaybill.basicFreightCalc(addWaybill.billing);
            });

            /********计算保费*********/
            $("input[name='waybillCargoValue']").on("change",function () {
                var cargoValue = $(this).val();
                var isMoney = /^\d+(\.\d{1,2})?$/;

                if(isMoney.test(cargoValue)){
                    var insuranceFee = parseFloat(cargoValue) * 0.003;
                    if (insuranceFee <= 5){
                        $("input[name='waybillInsuranceFee']").val("5.00");
                    } else {
                        $("input[name='waybillInsuranceFee']").val(insuranceFee);
                    }
                    addWaybill.incomeTotalCalc();
                } else {
                    layer.msg('金额格式错误！', {icon: 0, time: 1400});
                    $(this).val("");
                }
            });

            /********计算应收总额*********/
            $("input[name='waybillBasicFreight'],input[name='waybillPickupFee'],input[name='waybillDeliveryFee'],input[name='waybillInsuranceFee'],input[name='waybillUploadFee']").on("change",function () {
                var isMoney = /^\d+(\.\d{1,2})?$/;
                if (isMoney.test($(this).val())){
                    addWaybill.incomeTotalCalc();
                } else {
                    layer.msg('金额格式错误！', {icon: 0, time: 1400});
                    $(this).val("");
                }
            });

            /********计算付费*********/
            $("input[name='waybillIncomeTotal']").on('change',function () {
                if (addWaybill.payment != undefined && addWaybill.payment != ""){
                    addWaybill.paymentChange(addWaybill.payment);
                }
            });

        },
        basicFreightCalc:function () {
            if (this.billing == undefined || this.billing == ""){
                return false;
            }

            //数量
            var waybillCargoCount = $("input[name='waybillCargoCount']").val();
            //重量
            var waybillCargoWeight = $("input[name='waybillCargoWeight']").val();
            //体积
            var waybillCargoVolume = $("input[name='waybillCargoVolume']").val();

            //单价
            var waybillCargoPrice = $("input[name='waybillCargoPrice']").val();

            if (this.billing == "重量"){
                $("input[name='waybillBasicFreight']").val(waybillCargoPrice*waybillCargoWeight);
            }else if (this.billing == "体积"){
                $("input[name='waybillBasicFreight']").val(waybillCargoPrice*waybillCargoVolume);
            }else if (this.billing == "件数"){
                $("input[name='waybillBasicFreight']").val(waybillCargoPrice*waybillCargoCount);
            }else if (this.billing == "最低收费"){
                $("input[name='waybillBasicFreight']").val("");
            } else {
                $("input[name='waybillBasicFreight']").val("");
            }
            this.incomeTotalCalc();
        },
        incomeTotalCalc:function () {
            var isMoney = /^\d+(\.\d{1,2})?$/;

            var incomeTotal = 0;

            //基本运费
            var basicFreight = $("input[name='waybillBasicFreight']").val();
            //提货费
            var pickupFee = $("input[name='waybillPickupFee']").val();
            //送货费
            var deliveryFee = $("input[name='waybillDeliveryFee']").val();
            //保费
            var insuranceFee = $("input[name='waybillInsuranceFee']").val();
            //卸货费
            var uploadFee = $("input[name='waybillUploadFee']").val();

            //基本运费
            if (basicFreight != "" && isMoney.test(basicFreight)){
                basicFreight = parseFloat(basicFreight);
                incomeTotal += basicFreight;
            }
            //提货费
            if (pickupFee != "" && isMoney.test(pickupFee)){
                pickupFee = parseFloat(pickupFee);
                incomeTotal += pickupFee;
            }
            //送货费
            if (deliveryFee != "" && isMoney.test(deliveryFee)){
                deliveryFee = parseFloat(deliveryFee);
                incomeTotal += deliveryFee;
            }
            //保费
            if (insuranceFee != "" && isMoney.test(insuranceFee)){
                insuranceFee = parseFloat(insuranceFee);
                incomeTotal += insuranceFee;
            }
            //卸货费
            if (uploadFee != "" && isMoney.test(uploadFee)){
                uploadFee = parseFloat(uploadFee);
                incomeTotal += uploadFee;
            }
            //应收总额
            $("input[name='waybillIncomeTotal']").val(incomeTotal);

            //付费
            if (typeof(this.payment) != "undefined" && typeof(this.payment) != ""){
                this.paymentChange(this.payment);
            }
        },
        paymentChange:function () {
            $("input[name='waybillNowIncome'],input[name='waybillBackpayMonth'],input[name='waybillReachPay']").val("");

            //判断应收总额是否格式正确或非等空
            var incomeTotal = $("input[name='waybillIncomeTotal']").val();
            if (!(/^\d+(\.\d{1,2})?$/.test(incomeTotal) && incomeTotal != "")){
                return false;
            }

            //判断支付方式是否为空
            if (this.payment == undefined || this.payment == ""){
                $("input[name='waybillNowIncome'],input[name='waybillBackpayMonth'],input[name='waybillReachPay']").val("");
                return false;
            }

            //各种付款方式
            if (this.payment == "回付"){
                $("input[name='waybillBackpayMonth']").val(incomeTotal);
            }else if (this.payment == "到付"){
                $("input[name='waybillReachPay']").val(incomeTotal);
            } else {
                $("input[name='waybillNowIncome']").val(incomeTotal);
            }
        }
    }

    /**
     * 加载开单员，即当前登录员工账户
     */
    function loadNowLoginEmpInfo() {
        //加载开单员，即当前登录用户
        $.ajax({
            type: "POST",
            url: "/getLoginedEmp",
            success: function (data) {
                console.log(data);
                $("input[name='billingPersonName']").val(data['empName']);
                $("input[name='billingPersonName']").get(0).defaultValue = data['empName'];
                $("input[name='waybillBillingPerson']").val(data['empAccount']);
                $("input[name='waybillBillingPerson']").get(0).defaultValue = data['empAccount'];
            }
        });
    }

    /**
     * 生成运单主键
     * @returns {string}
     */
    function generateWaybillConsignNum() {
        var waybillConsignNum = "";
        var nowDate = new Date();
        var year,month,dayOfMonth,hourOfDay,minute,second = "";

        year = nowDate.getFullYear();
        month = nowDate.getMonth()+1;
        dayOfMonth = nowDate.getDate();
        hourOfDay = nowDate.getHours();
        minute = nowDate.getMinutes();
        second = nowDate.getSeconds();
        var uArr = ['Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M'];
        var lArr = ['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'];
        var randNum1 = Math.ceil(Math.random()*26);
        var randNum2 = Math.ceil(Math.random()*26);

        waybillConsignNum += (randNum1+randNum2)+""+uArr[randNum1]+lArr[randNum1]+year+month+dayOfMonth+hourOfDay+minute+second+"W";
        return waybillConsignNum;
    }

    /**
     * 加载发货方下拉列表
     */
    function loadShipperList() {
        $.ajax({
            type: "GET",
            url: "/getShipperList",
            success: function (data) {
                console.log(data);
                var optionS = "<option value=''>输入发货单位名称、发货人姓名、电话、发货号码地址、搜索发货方</option>";
                for (var i = 0; i < data.length; i++) {
                    optionS += "<option value='" + data[i]['shipperId'] + "'>"
                        + "<span class='shipperCom'>" + data[i]['shipperCom'] + "</span><span class='shipperPerson'>" + data[i]['shipperPerson'] + "，</span>"
                        + "<span class='shipperTelephone'><label class='shipper-hint'>联系电话</label>" + data[i]['shipperTelephone'] + "，</span>"
                        + "<span class='shipperAddress'><label class='shipper-hint'>发货地址：</label>" + data[i]['shipperAddress'] + data[i]['shipperDetailAddress'] + "</span>"
                        + "</option>";
                }
                $(".shipper-selectWrap > select[name='waybillShipperId']").children().remove();
                $(".shipper-selectWrap > select[name='waybillShipperId']").append(optionS);
                form.render("select");
            }
        });
    }

    /**
     * 加载收货方下拉列表
     */
    function loadConsiList() {
        //加载收货方列表
        $.ajax({
            type: "GET",
            url: "/getConsigneeList",
            success: function (data) {
                console.log(data);
                var optionS = "<option value=''>输入收货单位名称、发货人姓名、电话号码、收货地址、搜索收货方</option>";
                for (var i = 0; i < data.length; i++) {
                    optionS += "<option value='" + data[i]['consiId'] + "'>"
                        + "<span class='consiCom'>" + data[i]['consiCom'] + "</span><span class='consiPerson'>" + data[i]['consiPerson'] + "，</span>"
                        + "<span class='consiTelephone'><label class='consi-hint'>联系电话</label>" + data[i]['consiTelephone'] + "，</span>"
                        + "<span class='consiAddress'><label class='consi-hint'>发货地址：</label>" + data[i]['consiAddress'] + data[i]['consiDetailAddress'] + "</span>"
                        + "</option>";
                }
                $(".consi-selectWrap > select[name='waybillConsiId']").children().remove();
                $(".consi-selectWrap > select[name='waybillConsiId']").append(optionS);
                form.render("select");
            }
        });
    }

    /**
     *
     * @param selectOptions{elem,isNow} 包含选择器，是否是当前时间的对象，可以是数组
     * @returns {boolean}
     */
    function loadLayDate(selectOptions){
        if (typeof(selectOptions) != "object" || selectOptions === null){
            console.error("传入的选择器元素错误");
            return false;
        }

        if (typeof(selectOptions['elem']) == "string") {
            if (typeof(selectOptions['isNow']) != "undefined" && selectOptions['isNow'] === true){
                laydate.render({ //托运时间
                    elem: selectOptions['elem'], //指定元素
                    value: new Date(),
                    theme: "#5974d9"
                });
            }else {
                laydate.render({ //托运时间
                    elem: selectOptions['elem'], //指定元素
                    theme: "#5974d9"
                });
            }

        } else if (typeof(selectOptions['elem']) == "object" && selectOptions['elem'] instanceof Array) {
            for (var i = 0; i < selectOptions['elem'].length; i++) {
                if (typeof(selectOptions['isNow']) != "undefined" && selectOptions['isNow'] === true){
                    laydate.render({ //托运时间
                        elem: selectOptions['elem'][i], //指定元素
                        value: new Date(),
                        theme: "#5974d9"
                    });
                }else {
                    laydate.render({ //托运时间
                        elem: selectOptions['elem'][i], //指定元素
                        theme: "#5974d9"
                    });
                }
            }
        }






    }

    /**
     * 加载--分站--下拉框列表的方法
     * @param selectName 下拉框name,可以是str类型和arr类型
     */
    function loadSubstList(selectName) {
        $.ajax({
            type: "POST",
            url: "/getSubstationListFS",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    var li = "<option value='" + data[i]['substId'] + "'>" + data[i]['substName'] + "</option>";
                    if (typeof selectName == "string") {
                        $("select[name='" + selectName + "']").append(li);
                    } else if (typeof selectName != "undefined") {
                        for (var j = 0; j < selectName.length; j++) {
                            $("select[name='" + selectName[j] + "']").append(li);
                        }
                    }
                }
                form.render("select");
            }
        });
    }

    /**
     * 加载substId对应分站的司机列表下拉框
     * @param substId 分站id
     */
    function loadCarDriverList(substId) {
        $("select[name='waybillPickupDriver']").children().remove();
        $.ajax({
            type: "POST",
            url: "/queryCarsBySubst",
            data: {
                carPartofSubs: substId
            },
            success: function (data) {
                console.log(data);

                if (data.length == 0){
                    $("select[name='waybillPickupDriver']").append("<option>出发站无司机</option>");
                }

                var optionS = "";
                for (var i = 0; i < data.length; i++) {
                    optionS += "<option value='"+data[i]["carNumber"]+"'>"+data[i]["carDriver"]+"</option>";
                }
                $("select[name='waybillPickupDriver']").append(optionS);
                form.render("select");
            }
        });
    }

})